Try this
I think you can check that by checking the package name of your app with the package name of the activity that you from where you have navigated here
we can get the package name previous activity from the Activity Stack
ActivityManager am = (ActivityManager) context.getSystemService(Activity.ACTIVITY_SERVICE);
here you will get your package name ,
String packageName = am.getRunningTasks(1).get(0).topActivity.getPackageName();
String className = am.getRunningTasks(1).get(0).topActivity.getClassName();
And then get your current package name like this
String currentpackage = getApplicationContext().getPackageName();
Check whether two packages are same
i.e
if(packageName.equals(currentpackage))
{
Toast.makeText(context,"Same Application package",1).show();
}
it uses the permission in the manifest
<uses-permission android:name="android.permission.GET_TASKS" />
I hope this will help you