从另一个应用程序启动 Activity? (使用 AndroidAnnotations)

Launching Activity from another App? (with AndroidAnnotations)

如何在应用程序内部启动 AndroidAnnotations Activity_(主要) 由于外部 Activity(另一个应用程序)。

这是我当前的代码:

Intent codeScannerActivity = new Intent(PACKAGE, CODE_SCANNER_ACTIVITY);
codeScannerActivity.putExtra("codeScannerType", CameraUtils.CODE_SCANNER_SINGLE);
startActivityForResult(codeScannerActivity, Core.ActivityResult.RequestCode.CODE_SCANNER);

其中 = "main.app.package"

CODE_SCANNER_ACTIVITY = PACKAGE + ".activity.MyActivity_"

但日志抛出:

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=main.app.package dat=main.app.package.activity.MyActivity_ (has extras) }

Activity 在清单的主应用程序中使用 Class "etc.MyActivity_".

定义

您构建的 Intent 不正确。对于您正在使用的构造函数,第一个参数被解释为 "action",第二个参数被解释为 URI。该错误表明没有 activity 可以响应操作 "main.app.package" 和 URI "main.app.package.activity.MyActivity_".

要解决此问题,请先阅读 Starting Another Activity and the Intent javadocs from the Android Developer site. Especially look at the documentation for the available constructors. There might be one more appropriate for your purposes than the one you are trying to use. The Intent documentation has a list of standard Activity actions. If you want to start a specific activity, you should use Intent (Context packageContext, Class<?> cls):

Intent intent = new Intent(this, main.app.package.activity.MyActivity_.class);

我创建的 Intent 是错误的,这是正确的方法:

Intent codeScannerActivity = new Intent();
codeScannerActivity.setComponent(new ComponentName(PACKAGE, CODE_SCANNER_ACTIVITY));
codeScannerActivity.putExtra("codeScannerType", CameraUtils.CODE_SCANNER_SINGLE);
startActivityForResult(codeScannerActivity, Core.ActivityResult.RequestCode.CODE_SCANNER);