Is it safe to return from overriden getApplication() a shared static?
===

I am trying to limit a family of applications, using the same activity (in a Library Project shared by all), so that **only one** such application can run at a time.

In my first round of trying to learn how to go about that, I learned that:

 1. android:launchMode="singleTask" won't do the trick.
 2. `setVisible(true/false)` in onResume()/onPause() respectively is the [best way][1] to tell whether **my** application is running. But what do I do with it once the 2nd instance knows that the 1st instance is running???

So, I am thinking of tricking the system by always returning the same instance by overriding [Activity.getApplication()][2] and returning a shared static:

    @Override
    public class MyApplication extends Application 
    {   
        private static MyApplication s_instance;
    
        public MyApplication()
        {
            s_instance = this;
        }
    
        public static MyApplication getApplication()
        {
            return s_instance;
        }
    }

(credit for the idea goes to [@inazaruk][3])

But, like the aforementioned visibility solution, what do I do with this now?

Does the system itself use [getApplication()][4] to determine whether to launch a new instance or just bring it to the front of the stack? Is this safe?

If the answer is "no", can I just call [Activity.finish()][5] to not let the 2nd activity not even start? If so, where do I do this? Right in [Activity.onCreate()][6]? [Activity.onResume()][7]? A better place?


  [1]: http://stackoverflow.com/a/5862048/869501
  [2]: http://developer.android.com/reference/android/app/Activity.html#getApplication%28%29
  [3]: http://stackoverflow.com/a/6775509/869501
  [4]: http://developer.android.com/reference/android/app/Activity.html#getApplication%28%29
  [5]: http://developer.android.com/reference/android/app/Activity.html#finish%28%29
  [6]: http://developer.android.com/reference/android/app/Activity.html#onCreate%28android.os.Bundle%29
  [7]: http://developer.android.com/reference/android/app/Activity.html#onResume%28%29