在Android上,你怎么切换活动编程? [英] On Android, how do you switch activities programatically?

查看:118
本文介绍了在Android上,你怎么切换活动编程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好像每一个例子,我能找到的活动之间切换时,需要创建一个Intent,并通过与按钮关联的OnClickListener传入的视图中的上下文。

但如果你只是决定你需要切换的活动是什么?在我的情况下,preference值导致一个活动开关。

你如何创建一个意图,可能会导致一个活动开关没有关联的OnClickListener?

解决方案

 意图myIntent =新的意图(这一点,AvitivityName.class);
startActivity(myIntent);
 

应该为你做,你可以调用从您的其他活动的任何地方。

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.

How do you create an Intent that can cause an Activity switch without an associated OnClickListener?

解决方案

Intent myIntent = new Intent(this, AvitivityName.class);
startActivity(myIntent);

Should do it for you and you can call that from anywhere in your other activity.

这篇关于在Android上,你怎么切换活动编程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆