简体   繁体   中英

How to backpress pass an activity?

I have an activity that loads some content using an AsyncTask.

If the content is null then i launch an activty that contains a WebView to load the data.

The only problem is when i launch the activity using regular intents.

When the back button is pressed to return out of the WebView.

It returns to the following activity and the AsyncTask is ran again, and it does the same thing all over again.

I know how to Override the onBackPressed button. But what should i do to override this from happening each time?

If the content is null then when you launch the second Activity (with the WebView) you should call finish() on the first Activity.

EDIT: Alternatively you should use startActivityForResult and then in the onActivityResult method invoke finish() .

If you don't want to go back to the that loads the content, then call its finish() method after launching the WebView activity. The back button will then exit the app (or go to the activity before the loading one.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM