How to properly handle intents?

My application can view files of a certain type, and declares this in an intent-filter in its AndroidManifest.xml. My app launches fine, but I see some inconsistent behavior on different devices and different applications and am wondering if there is a best practice I am missing.

I often see this use case on some file browsers:

  • User selects a file and it opens in my application.
  • User presses home and then relaunches the file browser intent.
  • The filebrowser app launches, but with my application on top (if the user presses back, it will go back to the file browser).
  • Other times I see this more desirable use case:

  • User selects a file and it opens in my application.
  • User presses home and then relaunches the file browser intent.
  • The filebrowser app launches normally (if the user selects my application, it launches with the previously opened file active).
  • So, I wonder if this inconsistent is due to different implementations by the file browsers, or if there is something I should be doing to properly handle intents, like some way of "releasing" the application that launched my app?


    I think your problem is not handling intents, but handling the activity stack. You can explicitly finish() your 'launcher' activity (as classified in the AndroidManifest.xml). You can also 'put' a vflag in your filebrowser intent which indicates as to when the app should follow what sequence of activities. For eg., if you want the filebrowser to start directly, you could search the intent for that flag and depending upon its value finish() the launcher activity and start the filebrowser actvitiy directly OR continue as per your original sequence of activities.

    链接地址: http://www.djcxy.com/p/41880.html

    上一篇: 如何知道应用程序将在android中被卸载?

    下一篇: 如何正确处理意图?