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