Reputation: 1042
I know that finish() returns your activity back to your previous activity. Now I am curious if we are able to accomplish the opposite meaning forwarding back to the next activity that you backed off without doing an Intent. This is just a curiosity question.
Is this possible?
Upvotes: 2
Views: 433
Reputation: 70
NO,because once you call the finish() method,it will destroy that corresponding activity.The only way to accompanish your task is by using an intent.
Upvotes: 0
Reputation: 1048
Short answer: No, because The activity that finish()ed was destroyed.
Long answer: From the Activity Documentation
onDestroy() - The final call you receive before your activity is destroyed. This can happen either because the activity is finishing (someone called finish() on it, or because the system is temporarily destroying this instance of the activity to save space.
Calling finish() doesn't actually guarantee immediate GC on the activity, but it will be made eligible soon after a call to finish(). You can assume that anything in the activity instance is gone if it wasn't persisted. Don't hold references to Activities that Android says should be killable, per Activity Lifecycle and Avoiding Memory Leaks, this is not a way to get around this, and is a Bad Idea(tm).
You could override OnDestroy() and check isFinishing() if you'd like to store the activity history in your application, so that you can manually implement something like "forward" functionality, but in general it's better practice to do something like that in onSaveInstanceState().
Upvotes: 2
Reputation: 1243
No, that is not possible, once you run finish() (or press back) on an activity it will be poped from the activity stack and al its content garbage collected, only way to reach if again is by starting it with and intent.
Upvotes: 3
Reputation: 1006604
No. The "next activity that you backed off without doing an Intent" was destroyed by a call to finish()
when the user pressed BACK, so you cannot return to it.
Upvotes: 4