开发者

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.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜