Skip to content Skip to sidebar Skip to footer

Start Activity Of Main Project From My Library Project

I have 2 projects. One is my Main Project(A) , and another is a Library Project(B). I want to start an activity which is present in A from an activity which is located in B. How do

Solution 1:

You shouldn't need to use an intent filter. The code in Activity A can use

ComponentNamecn=newComponentName(this, "my.package.MyActivity.B");
Intentintent=newIntent().setComponent(cn);

startActivity(this, intent);

to specify the activity B should be started.

Solution 2:

You can add custom Action in intent-filter of you activity and start that activity by specifying action

<activityandroid:name="my.package.MyActivity"><intent-filter><actionandroid:name="my.package.action.MY_ACTION"/><categoryandroid:name="android.intent.category.DEFAULT" /><categoryandroid:name="my.package"/></intent-filter></activity>

start activity with this code:

finalIntentintent=newIntent("my.package.action.MY_ACTION");
intent.addCategory(getActivity().getPackageName());
startActivity(getActivity(), intent);

Post a Comment for "Start Activity Of Main Project From My Library Project"