If you have several activities onPause() is there a way to finish a specific activity?
edit: so for example, imagine on start activity 1 is called. Then activity 1 uses an intent to go to activity 2. then an update is made to the database and calls act开发者_开发问答ivity 1_new again so that it displays the updated database. At that point i want to get rid of the old activity 1.
It depends on what you want to do. You'll need to look at the AndroidManifest.xml spec for activity calls stacks.
Specifically android:launchMode
<activity android:launchMode="singleTop">
Careful though, launchModes are very tricky and can get you into trouble since it also depends on how the activity is launched from the Intent itself.
singleTop will essentially keep only 1 instance of that activity in the stack.
From the Docs:
If an instance of the activity already exists at the top of the target task, the system routes the intent to that instance through a call to its onNewIntent() method, rather than creating a new instance of the activity.
What I ended up doing here was calling startActivityForResult in the first activity. That way I was able to redisplay updated information from the second activity.
精彩评论