怎样的android完成其他活动活动

编程入门 行业动态 更新时间:2024-10-19 09:37:09
本文介绍了怎样的android完成其他活动活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在我的应用程序,我有3项活动。

In my app i have 3 activities.

这是第一次活动就进入第二个和第二个它进入第3位。从第三是来第一次了。如果我preSS返回键从第一话就应该到主屏幕(应用程序将停止)。 如果我preSS回第一次的关键它去再第二活性,如果我preSS 2日的返回键,然后将其转到第一。然后,如果我preSS回第一次的键,然后程序停止。

From 1st activity it goes to 2nd and from 2nd it goes to 3rd. From 3rd it is coming to 1st again. and if I press back key from the 1st then it should go to home screen (App will stop). If I press back key of 1st its goes to 2nd activity again and if I press 2nd's back key, then it goes to the 1st . Then if I press back key of 1st then app stops.

我要什么,当我在第3次活动,preSS后退按钮,那么就应该去第一,同时完成第二次活动。

What I want , when I am in 3rd activity and press the back button then it should go to 1st and simultaneously finish the 2nd activity.

我怎么能这样做?

推荐答案

只是完成了第二个活动,当您打开第三个活动

just finish the second activity when you open third activity

假设在某些按钮次活动单击您要打开使用Start活动第三个活动;

suppose in second activity on some button click you are opening third activity using start activity;

startActivity(intent); finish();//this will finish second activity and open third activity so when you press back from third activity it will open first activity.

如果你想依赖于某些条件,那么在活动

if you want depended on some condition then on activity

setResult(123);

东西code这样

something code like this

现在当次活动覆盖onActivityResult

now when override onActivityResult in second activity

@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if(resultCode==123){ //finish } }

也确保一件事,你需要使用startActivityForResult(意向,要求code);对于导致第二个活动开始第三个活动。

also make sure one thing you need to use startActivityForResult(intent, requestCode); for result in second activity to start third activity.

import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; public class Activity2 extends Activity{ Button button; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main1); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startActivityForResult(new Intent(new Intent(Activity2.this,Activity3.class)), 12); } }); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if(resultCode==123 && requestCode==12){ finish(); } super.onActivityResult(requestCode, resultCode, data); } } import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.Button; public class Activity3 extends Activity{ Button button; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main1); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { setResult(123); } }); } }

更多推荐

怎样的android完成其他活动活动

本文发布于:2023-11-27 03:59:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636489.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!