简体   繁体   中英

Launching Activity from another App? (with AndroidAnnotations)

How can i launch an AndroidAnnotations Activity_ inside of an App (main) since external Activity (another App).

this is my current code:

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

where PACKAGE = "main.app.package"

and CODE_SCANNER_ACTIVITY = PACKAGE + ".activity.MyActivity_"

but logs throws:

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

Activity is defined in the Manifest's Main App with the Class "etc.MyActivity_".

You are constructing the Intent incorrectly. For the constructor you are using, the first parameter is interpreted as an "action" and the second as a URI. The error says that there is no activity which can respond to the action "main.app.package" and the URI "main.app.package.activity.MyActivity_".

To fix the problem, first read 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);

I was creating wrong the Intent, this is the right way:

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);

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM