如何跳过活动?安卓
我有一个首先启动的默认活动(活动 A),然后用户可以从那里转到另一个活动(活动 B)。在 B 中,经过一些工作后,用户设置了共享首选项。下次应用程序启动时,我想检查 A 是否共享首选项为空,然后转到 B。我将其放在下面
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
,它封装了整个 onCreate。当应用程序启动时,它会跳过 A 并在 B 上显示布局和带有 NullPointerException 的 FC。
有人有这方面的经验吗?
或者
有人对跳过 A 有更好的主意吗?
i have a default activity that starts first (Activity A), and from there the user can go to another activity (Activity B). In B after some work the user sets a sharedpreference. the next time the app starts i want to check in A if sharedpreference is null to go to B. and i put this if just under
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
and it encapsulates the whole onCreate. when the app starts it skips A and on B i shows the layout and the FC with NullPointerException.
Any one got experience with this?
OR
any one got a better idea on skipping A?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,西蒙,你必须使用共享首选项。将您的数据保存在共享首选项中。然后,在您想要使用共享首选项中的数据的活动中,再次获取相同共享首选项的实例。获取数据并使用它。
通过这段代码
你可能会有所了解
Well Simon you have to use Shared prefrences. save your data in shared prefrences. Then in the activity where you want to use the data in Shared prefres again get instance of same shared prefrence. get the data and use it.
go through this code
probably you will get an insight
回答我自己的问题。我在 onDestroy 中有一个位置监听器,因为它没有初始化,因为跳过 onCreate 它返回了 NullPointer。
To answer my own question. i had a location listener in onDestroy an because it was not initialized because of skipping onCreate it returned NullPointer.