本文介绍了如何活动之间进行切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的应用程序,我有三个活性
-
活动1
-
活动2
-
活动3
如何活动之间进行切换。
那么,如何才能做到这一点?
公共布尔onOptionsItemSelected(菜单项项)
{
开关(item.getItemId())
{
案例R.id.settingOpt:
意向意图=新的意图(这一点,SettingsForm.class);
this.startActivity(意向);
this.finish();
打破;
案例R.id.reminderOpt:
意图intentR =新的意图(这一点,ReminderForm.class);
this.startActivity(intentR);
打破;
案例R.id.helpOpt:
意图intentH =新的意图(这一点,HelpForm.class);
this.startActivity(intentH);
this.finish();
打破;
案例R.id.shareOpt:
意图份额=新的意图(android.content.Intent.ACTION_SEND);
share.setType(text / plain的);
share.putExtra(Intent.EXTRA_SUBJECT的东西分享名称);
share.putExtra(Intent.EXTRA_TEXTwww.gmail.com);
startActivity(Intent.createChooser(份额,共享LoveCycle的网站链接你的朋友));
打破;
默认:
返回super.onOptionsItemSelected(项目);
}
返回true;
}
解决方案
使用以下对Activity3后退按钮preSS事件方法:
的setResult(R.id.common_backToActivity1);
和中活性2捕获的setResult如下,然后关闭此活动:
保护无效onActivityResult(INT申请code,INT结果code,意图数据){
开关(结果code){
案例R.id.common_backToActivity1:
closeActivity(); //完成活性2在此方法
打破;
}
super.onActivityResult(要求code,因此code,数据);
}
然后你会得到直接到活动1。
In my app I have three activity as
Activity 1
Activity 2
Activity 3
How to switch between activities.
So how can this be done?
public boolean onOptionsItemSelected(MenuItem item)
{
switch (item.getItemId())
{
case R.id.settingOpt:
Intent intent = new Intent(this, SettingsForm.class);
this.startActivity(intent);
this.finish();
break;
case R.id.reminderOpt:
Intent intentR = new Intent(this, ReminderForm.class);
this.startActivity(intentR);
break;
case R.id.helpOpt:
Intent intentH = new Intent(this, HelpForm.class);
this.startActivity(intentH);
this.finish();
break;
case R.id.shareOpt:
Intent share = new Intent(android.content.Intent.ACTION_SEND);
share.setType("text/plain");
share.putExtra(Intent.EXTRA_SUBJECT, "Name of the thing to share");
share.putExtra(Intent.EXTRA_TEXT, "www.gmail.com");
startActivity(Intent.createChooser(share, "Share LoveCycle's website link with your friends"));
break;
default:
return super.onOptionsItemSelected(item);
}
return true;
}
解决方案
Use following method on back button press event in Activity3:
setResult(R.id.common_backToActivity1);
And in Activity2 capture that setResult as follows and close this Activity:
protected void onActivityResult(int requestCode, int resultCode,Intent data) {
switch(resultCode){
case R.id.common_backToActivity1:
closeActivity(); //Finish Activity2 in this method
break;
}
super.onActivityResult(requestCode, resultCode, data);
}
Then you will get directly to Activity1.
这篇关于如何活动之间进行切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!