1

I want to know if my app was executed by another app

I tried several methods but I could not find a solution

I tried this but returns the same value please help me! Code:

public class MainActivity extends Activity {

    public static boolean isinint;

    @Override
    protected void onResume() {
        super.onResume();

        Intent intent = getIntent();
        // check if any application has executed your app
        if (intent != null && intent.getType() != null) {
            isinint = true; 
            Toast.makeText(getApplicationContext(), "is:" + isinint, Toast.LENGTH_LONG).show();
        } else {
            isinint = false; 
            Toast.makeText(getApplicationContext(), "is:" + isinint, Toast.LENGTH_LONG).show();
        }
    }
}
Kuba Spatny
  • 26,618
  • 9
  • 40
  • 63
  • 1
    possible duplicate of [Differentiating between an Activity launch from home screen or from another activity from App](http://stackoverflow.com/questions/5637876/differentiating-between-an-activity-launch-from-home-screen-or-from-another-acti) – vault May 11 '15 at 09:29
  • not is a duplicate does not solve any problem – francescofalletta May 11 '15 at 09:41
  • did u try the solution? if yes what r the values displayed – Rajen Raiyarela May 11 '15 at 09:55
  • how about when you launch an activity yourself pass data to your intent, when your activity is launched by another app you can check that data – TomTsagk May 11 '15 at 10:34
  • possible duplicate of [How can i check if an app running in Android?](http://stackoverflow.com/questions/4212992/how-can-i-check-if-an-app-running-in-android) – Thealon Sep 24 '15 at 12:23

1 Answers1

1

This answer from dhaval will work for you

Try this code:

      ActivityManager activityManager = (ActivityManager) this.getSystemService( ACTIVITY_SERVICE );
         List<RunningAppProcessInfo> procInfos = activityManager.getRunningAppProcesses();
         for(int i = 0; i < procInfos.size(); i++)
         {
             if(procInfos.get(i).processName.equals("com.android.browser")) 
             {
                 Toast.makeText(getApplicationContext(), "Browser is running", Toast.LENGTH_LONG).show();
             }
         }

replace com.android.browser with your app process name.

Community
  • 1
  • 1
Thealon
  • 1,935
  • 1
  • 13
  • 22