Android 程序之间的跳转
2017-10-12 本文已影响7人
自然之秋
private void initonClick() {
btnCountDown.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
//知道包名,则直接跳
//goTo(SplashActivity.this,"com.dazheng");
//跳具体Activity还有些问题,只能跳启动页,先放着研究一下
goToAPP(SplashActivity.this, "com.dazheng");
} catch (Exception e) {
LogUtils.e(TAG, " 报错 = " + e);
}
}
});
}
public void goToAPP(Context context, String packagename) {
Intent intent = new Intent();
PackageManager packageManager = context.getPackageManager();
intent = packageManager.getLaunchIntentForPackage(packagename);
ComponentName comp = new ComponentName(packagename, "com.dazheng.WelcomeActivity");
intent.setAction("android.intent.action.VIEW");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setComponent(comp);
context.startActivity(intent);
}
public void goTo(Context context, String packagename) {
Intent intent = new Intent();
PackageManager packageManager = context.getPackageManager();
intent = packageManager.getLaunchIntentForPackage(packagename);
intent.setAction("android.intent.action.VIEW");
context.startActivity(intent);
}