Hi I am working on my custom launcher. My custom launcher is set to default launcher and I need to call the android's basic launcher once a user clicks a button programmatically. I have searched out a lot and found out I cannot just turn off the application so finish() and exit(0) are not working. All I found it I just need to call the android's basic launcher but it is very hard to get the final answers. Here is what I have:
PackageManager pm=getPackageManager();
Intent main=new Intent(Intent.ACTION_MAIN, null);
List<ResolveInfo> launchables=pm.queryIntentActivities(main, 0);
Collections.sort(launchables, new ResolveInfo.DisplayNameComparator(pm));
for(int i=0;i<launchables.size();i++) {
//find android's basic launcher package
if(launchables.get(i).toString().contains("com.android.launcher")) {
//open a package
ResolveInfo launchable = launchables.get(i);
Util.print(launchable.resolvePackageName);
Intent intent = pm.getLaunchIntentForPackage(launchable.resolvePackageName);
startActivity(intent);
}
}
I know this code is quite silly to find and call a package. This code calls the Android's setting and second call makes an error. I am pretty sure this code is not good, I just want you to know what I am trying to do now. Can anyone tell me how to open Android's basic launcher?
Edited with temporary solution
ComponentName name=new ComponentName("com.android.launcher", "com.android.launcher2.Launcher");
Intent intent = new Intent();
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
intent.setComponent(name);
startActivity(intent);