Android explicit intent with target component

后端 未结 5 1468
鱼传尺愫
鱼传尺愫 2020-12-09 03:45

Is it possible to fire explicit intent but not for an activity from my project but for activity in some other application.

I am sure of this code and I know it is ru

5条回答
  •  天涯浪人
    2020-12-09 04:44

    I'd suggest to concatenate the package & class name with a dot;

    this speeds up copy & paste, eg. while writing jUnit tests.

    String packageName = getApplicationContext().getPackageName();
    String className = "SomeActivity";
    
    Intent intent = new Intent();
    intent.setComponent(new ComponentName(packageName, packageName + "." + className));
    startActivity(intent);
    

提交回复
热议问题