In our Android application I implemented the contact selection by using Intent action *ACTION_PICK* on the *ContactsContract.Contacts.CONTENT_URI*. This method works fine (mostly), but unfortunately I have no control over the incoming events activity.
The app have to log out and quit when it is enforced into the background. At the moment it is implemented by making use of the activity event: onStop() for the main activity, but obviously the app won’t receive that event if the contacts activity from the system is open.
I have tried to subclass the contact activity somehow, but I am afraid it cannot be managed.
I tried to use different activity start flags, but couldn’t find any relevant flag for this situation (not to mention that flags are not working with startActivityForResult() method).
I tried to hook into different broadcasted events, but there are way too many possibilities that ends up pushing the app to the background.
I have found some tricks for polling the application on the top, but that would require GET_TASKS permission and generally it would be a major hack anyway. I would rather not go there.
So, to sum up my question:
Is there any way to detect that the application is enforced into the background while the contact activity is open?
Finally, my colleague found the answer:
Add the following properties to the main activity:
And after the user pressed the home button while the contact selection was open and relaunched the app a new event will be triggered on the main activity:
The cancel result code is still coming back similarly like when the user pressed the back button on the contact selection activity, but in that case this specific event won’t be triggered.
This way I can differentiate between the situations when the user closed down the contact activity and when the system closed it down.