Force stop another app?

Kevin

Well-Known Member
Licensed User
Longtime User
Both my free & paid versions of my app now allow notifications to be shown. One issue I have due to this is that if the user buys the paid version then runs it, they have two notifications visible. One from the free version and one from the paid one.

Is there any way to force stop an app that is not the one you are actually running? I'd like to kill the free version (if running) when the paid version is opened.

It must be possible (task killers) but my searches aren't finding anything unless I am not phrasing it well.
 

Kevin

Well-Known Member
Licensed User
Longtime User
In your free version you can detect the package name of the paid version and start it instead of running the free one.

Sent from my GT-I9000 using Tapatalk 2

I already do that (and also offer to uninstall the free version), but I'm trying to avoid two notification icons if they have the free one running then decide to buy and run the paid one without fully exiting the free version first.


NJDude: Thanks. I'll check out the lib.
 
Upvote 0

raytronixsystems

Active Member
Licensed User
Longtime User
Here's a very simple solution:

You could have your Paid App periodically look for the existence of a "kill" file (i.e. KILLREQFILE) on a timer(to conserve battery life). This file does not have to have anything in it. If the file exists it would delete it and perform a graceful exit. The Free App would create the KILLREQFILE whenever it is time to kill off the paid peer app. The Free App would not create the file it if it already existed. I could even check to see if it's KILLREQFILE was deleted after created and log the fact that the Paid App was successfully killed off since no other process in the system would ever delete the kill file under in normal circumstances. To insure integrity, The Free App would have to detect the existence of the KILLREQFILE at least once to insure that it was indeed created before assuming that the Paid App was truly killed off. Before EXITING, the Paid App could write another file KILLACK FILE to notify the Free App that it detected the KILLREQFILE and did it's exit. The idea here is synchronization so that files aren't left around when they shouldn't be in case of a process failure or intervention by the User. Make sure that the Free App deletes the KILLACKFILE and KILLREQFILE if they exist when the app is started.

I've done this sort of thing in other programming languages as sort of a poor man's semaphore and messaging system.

Try it out. It should work well and does not involve any system libraries or PID's, etc. You could test it manually by creating the kill file yourself and see if your App deletes the file and exits.

By using two different files each version of your app can insure that it is the only one running. Just reverse the logic described above.

I think I'll implement this in my next project myself... Simple yet elegant.

Regards,
Ray
 
Last edited:
Upvote 0

Kevin

Well-Known Member
Licensed User
Longtime User
I might consider something like the kill file idea but I don't know if it will work for my situation. For now I've updated my paid app with a simple warning if the free version is installed and pro version is run (FirstRun) that there could be duplicate notifications if the free version is already running and offers to open the free version to allow the user to exit if they want to.

Killing the process was not getting rid of the notification. Probably by design, but it didn't help me. Killing the free version FROM the free version would close the notification, but it would have to be "active" before it can even check to see if it should be killed.

I actually left the OS library in originally to use it to see if the process was active before bothering to tell the user, but when I uploaded it to the market and saw that my app went from 3 permissions to 10, I freaked out. I don't think my customers would have liked some of those permissions. :SHOCKED: So, I went with the simple check to see if it is installed which requires no extra permissions.
 
Upvote 0
Top