android How to switch between Intents

故事扮演 提交于 2020-01-15 10:37:28

问题


I have 3 activities. start / game / finish, I want to go start to game, game to finish, finish to start. but when I use Intent one to another when I finish() "finish" Its come back to game. It should come back to start. so It needs a design kind of all Intents under start activity.

so I tried this one and expected when I finish() "finish" application will be destroy but It didnt work

Intent intent = new Intent(getApplicationContext(),FinishScreen.class); 
startActivity(intent);

Q: so how can I start finish activity Intent under start activity but from game activity


回答1:


When you call startActivity(...) in "game" Activity to start the "finish" Activity, immediately call finish() so "game" terminates. If you do that then BACK in the "finish" Activity will return to "start" because "game" self-terminated.

Intent intent = new Intent(getApplicationContext(),FinishScreen.class); 
startActivity(intent);
finish();



回答2:


The finish() method should work, try with: System.exit(0);



来源:https://stackoverflow.com/questions/8858229/android-how-to-switch-between-intents

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