美文网首页
Android 程序之间的跳转

Android 程序之间的跳转

作者: 自然之秋 | 来源:发表于2017-10-12 10:35 被阅读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);
    }

    相关文章

      网友评论

          本文标题:Android 程序之间的跳转

          本文链接:https://www.haomeiwen.com/subject/kpenyxtx.html