aryaxt
aryaxt

Reputation: 77596

Android - Opening a webpage and back to Activity?

Let's say I am on an Activity, user clicks a button, and I navigate to a web page.

Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("SOME_URL"));
startActivity(i);

it takes me to the web page, and then when I click back to goes to my activity, but it starts it all over again. So is it possible to do this in a way so that after clicking the back button, it takes me to my activity, but instead of onCreate it call onRestart. The goal is not going through onCreate again.

Upvotes: 0

Views: 1149

Answers (2)

WarrenFaith
WarrenFaith

Reputation: 57672

That is the normal life cycle of an Activity... you could save the state of the activity and restore it to get the "same" as before.

The main question should be: Why do you not want to go through onCreate? If it goes through it because it was destroyed before and need to be recreated. So not going through it will cause a lot of trouble.

Upvotes: 1

Snicolas
Snicolas

Reputation: 38168

You could set an intent in your activity (setIntent) before calling the web browser, then in your onCreate method, check for if this intent called you back (check the intent name or an extra) and if so, skip the rest of onCreate.

Before calling web browser :

Intent intentForThis = new Intent( "AfterWebBroswer" );
this.setIntent( intentForThis );

Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("SOME_URL"));
startActivity(i);

And then in your onCreateMethod

public void onCreate( Bundle b ) {
    if( !getIntent().getAction().equals("AfterWebBrowser") ) {
       //rest of onCreate
    }//if
}//met

Regards, Stéphane

Upvotes: 0

Related Questions