This is very strange - I'm trying to programmatically open another app. I found this link which I followed : Stackoverflow link
So my code is as follows - note it is being run inside a dialog.
Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
intentToResolve.addCategory(Intent.CATEGORY_HOME);
intentToResolve.setPackage("com.android.launcher3");
intentToResolve.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
ResolveInfo ri = getPackageManager().resolveActivity(intentToResolve, 0);
if (ri != null)
{
Intent intent = new Intent(intentToResolve);
intent.setClassName(ri.activityInfo.applicationInfo.packageName, ri.activityInfo.name);
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
startActivity(intent);
}
This seems to only "close" my app and go to the home screen if I put a breakpoint in the code. If I just let it run with no breakpoint then nothing happens.
I have no idea why it would do this? Any ideas? Thanks.
Edit: I've uploaded a video of it happening to YouTube so you can see exactly what I mean. You'll see the first time I run it, it hits the breakpoint and the device goes to the home screen. The second time I run it I have removed the breakpoint and nothing happens. YouTube link