I dont know what I am doing wrong. I am trying to launch an activity of another app from current app.
Here is the code:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName("com.second.package","com.second.package.SecondActivity"));
startActivity(intent);
}
When I run this thing it says Application closed unexpectedly. What is wrong? Please help me.
Succeded: Just add :
android.intent.category.DEFAULT
to the activity in the manifest file.
try as:
Intent intent = new Intent("android.intent.action.MAIN");
intent.setComponent(new
ComponentName("com.second.package","com.second.package.SecondActivity"));
intent.addCategory("android.intent.category.LAUNCHER");
intent.setFlags(Intent.FLAG_FROM_BACKGROUND);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.