Reputation: 345
Is this possible to check if currently my app is in background and home screen is launched
Upvotes: 3
Views: 5313
Reputation: 379
Try this function,
public boolean isUserIsOnHomeScreen() {
ActivityManager manager = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
List<RunningAppProcessInfo> processes = manager.getRunningAppProcesses();
for (RunningAppProcessInfo process : processes) {
if(process.pkgList[0].equalsIgnoreCase("com.android.launcher")) {
return true;
} else {
return false;
}
}
return false;
}
Upvotes: 3
Reputation: 345
if (apps.get(0).topActivity.getPackageName().equals("com.android.launcher")
this somehow solved my problem only for default home
Upvotes: 5
Reputation: 49
Wether use onPause/onStop and onResume methods for activity purposes, or make advantage with an own implemented service for backround-processing (based on time-delays or messages/receivers).
Upvotes: 1
Reputation: 98501
There is no API to know whether the home screen is showing. However you can know when your app is sent to the background using the various Activity lifecycle callbacks (onStop, etc.)
Upvotes: 7