Reputation: 1
After executing the below code Activity
of my app gets closed but till component name, code is working fine:
PackageManager pm = getPackageManager();
PackageInfo packageInfo = pm.getPackageInfo("com.package.address",PackageManager.GET_ACTIVITIES);
ActivityInfo[] activitiesInfos = packageInfo.activities;
ActivityInfo activityToLaunch=activitiesInfos[0]; //<< activity which want enter code here to enter code herestart
// Create ComponentName object using packageName and activity name
ComponentName compName=new ComponentName(
activityToLaunch.applicationInfo.packageName,
activityToLaunch.name);
Intent intent=new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setComponent(compName);
startActivity(intent);
While debugging cursor come till startActivity(intent)
but after this activity will terminate
Upvotes: 0
Views: 45
Reputation: 296
Ok, please try below:
1.) if you just want to start the launcher activity of another app:
Intent intent = getPackageManager().getLaunchIntentForPackage("com.package.address");
if (intent != null) {
// if package is found; otherwise null
startActivity(intent);
}
2.) if you want to start a specific activity (note: you need to know its full name and it should be set android:exported="true"
in AndroidManifest)
Intent intent = new Intent();
// xxx and yyy representing its sub package if any
intent.setComponent(new ComponentName("com.package.address", "com.package.address.xxx.yyy.FullActivityName"));
startActivity(intent);
Upvotes: 2