I want to automatically open app when receive push notification. I\'ve tried but it still does not work as I expected. This code below is work when the app is active or in M
Firstly, the concept of "application" in Android is slightly an extended one.
An application - technically a process - can have multiple activities, services, content providers and/or broadcast listeners. If at least one of them is running, the application is up and running (the process).
So, what you have to identify is how do you want to "start the application".
Ok... here's what you can try out:
action=MAIN
and category=LAUNCHER
PackageManager
from the current context using context.getPackageManager
packageManager.queryIntentActivity(, 0)
where intent has category=LAUNCHER, action=MAIN
or packageManager.resolveActivity(, 0)
to get the first activity with main/launcherActivityInfo
you're interested inActivityInfo
, get the packageName
and namecategory=LAUNCHER, action=MAIN, componentName = new ComponentName(packageName, name)
and setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)context.startActivity(newIntent)