Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
634 views
in Technique[技术] by (71.8m points)

java - Android - How to start the exact same activity every time the app is opened up?

In a nutshell, to give you an example, I basically have an app with 3 activities: Activity1 Activity2 StartActivity

StartActivity contains two buttons that correspond to the other two activities respectively, starting them up. If I exit the application from Activity1, when I later click on the app icon from the phone, Activity1 is restarted since Android keeps track of this. I need to have the app restart to bring me to the StartActivity, so that I can choose where to go by clicking the buttons, instead of having to click the back button to be able to end up at the StartActivity. I'm assuming onResume and onRestart are involved, but where should they go?

Any help is greatly appreciated thank you.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You might look at the android:clearTaskOnLaunch activity attribute from the Manifest file : http://developer.android.com/guide/topics/manifest/activity-element.html

I think setting this attribute to "true" on your root activity does what you want.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...