本文介绍了在 Android 上,如何以编程方式切换 Activity?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
似乎我能找到的在 Activity 之间切换的每个示例都涉及创建 Intent 并通过与按钮关联的 OnClickListener 在 View 的上下文中传递.
It seems like every example I can find of switching between activities involves creating an Intent and passing in the context of a View via an OnClickListener associated with a button.
但是,如果您只是决定需要切换活动怎么办?就我而言,偏好值导致活动切换.
But what if you just decide you need to switch activities? In my case, a preference value is causing an Activity switch.
如何在没有关联 OnClickListener 的情况下创建可以导致 Activity 切换的 Intent?
How do you create an Intent that can cause an Activity switch without an associated OnClickListener?
推荐答案
这应该适合你:
Intent myIntent = new Intent(this, MyActivityName.class);
startActivity(myIntent);
您可以在当前活动的任何位置调用它.
You can call that from anywhere in your current activity.
这篇关于在 Android 上,如何以编程方式切换 Activity?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!