Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a certain activity in Android Studio?

Tags:

For instance, I have a few activities within one app, and in order to see a certain activity's UI or whatever, I need to run a certain activity that is not the launcher of the app.

One stupid way is to build a "door" for that activity in the launcher and go inside the activity from the door. However, Is there any better way to run a certain activity alone?

like image 306
guo Avatar asked Jul 11 '16 13:07

guo


People also ask

How do I run an activity from another application?

If both application have the same signature (meaning that both APPS are yours and signed with the same key), you can call your other app activity as follows: Intent LaunchIntent = getActivity(). getPackageManager(). getLaunchIntentForPackage(CALC_PACKAGE_NAME); startActivity(LaunchIntent);

How do I make another activity as main activity?

If you want to make Login activity your main activity then put the the intent-filter tag inside Login activity. Any activity your want to make your main activity must contain intent-filter tag with action as main and category as launcher.


1 Answers

Very easy. Start by exporting the activity you need to run:

Add android:exported="true" in the Activity declaration in the Manifest. This is because am is an external application, and you need to export Activities to allow external application to start them.

Go to "Edit Configurations..." in the "Run" menu.

In the left pane, select your application. In the right pane, in the "General" tab, in the "Launch Options" section, there is a "Launch:" dropdown.

Select "Specified Activity", and enter the name of your activity as it appears in your Manifest.

You can create as many Configurations as you like, and name them according however you like, for example to indicate which activity is being started.

like image 129
njzk2 Avatar answered Sep 18 '22 17:09

njzk2