Activity lifecycle issues

匿名 (未验证) 提交于 2019-12-03 10:03:01

问题:

I have 3 activities running ,navigating a1 to a2 then a2 to a3.Now pressing back button from emulator,I want to go to the activity a1 without finishing activity a2.How can i do this..Please guide me..Thanks in advance

回答1:

Yes you can override that back button

public void onBackPressed() {   Intent start = new Intent(currentclassname.this,which activity u want.class);     startActivity(start);     finishActivity(0);  }

By this you can move on any activity. This is very easy and simple way



回答2:

Try this in your A3 activity's back key event:

 Intent intent = new Intent(this,A1.class);  intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);  startActivity(intent);


回答3:

Write this thing in a3

@Override public void onBackPressed() {     // TODO Auto-generated method stub     Intent intent=new Intent(getApplicationContext(),a1.class);     intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);     startActivity(intent);  }


回答4:

Activity 2 does not have to die. Just implement the onPause() and onResume() methods o hold and restore the activity state.

http://developer.android.com/reference/android/app/Activity.html

The life cycle diagram is helpful. To control he way activities are generated and moved on he stack you can adjust the manifest activity properties or add flags to the calling intent.



回答5:

You can also implement this from your AndroidManifest.xml file, just adding android:noHistory="true" attribute in those you want.



回答6:

In a2 activity

you can overide the restart() as below::

@Override protected void onRestart() { // TODO Auto-generated method stub super.onRestart(); startActivity(new Intent(getApplicationContext(),a1.class)); }


转载请标明出处:Activity lifecycle issues
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!