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