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.)
精彩评论