Multiple Activities = multiple Apps installed? - android

I'm just getting started with the Android SDK and after I just understood how to open another view with a MenuItem. I'm now facing a problem that it is showing me my two activities as separated applications installed?
I've created a new activity and a new xml file (layout) and when I touch the menuItem in the ActionBar in my first view it opens the second view.
Any idea to work around that?

It sounds like you have the <intent-filter> set as
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
for both activities. This will create a launcher icon for each and make each an entry point for your app
Docs

Most likely, you've included the following intent filter in both your Activities:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
This is meant to be put in only those Activities which you want shown in the app list.

Related

Two icons created when using two activities

Two icon created when i using Two activity Android Studio.
I don't know why is this.
I delete intent and I do some works but it's didn't worked.
I am creating one app.
And I run in physical device.
And that app has two icons.
I find my problem and I will clear .
`
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>`
here you will two category . you will delete number two category .
This is our problem . android.intent.category.LAUNCHER this create a app icon for second activity.
Just remove these lines from one of your two activities (if you have a SplashScreen and a MainActivity, remove them from your MainActivity)
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Answer from https://stackoverflow.com/a/29735556/8577483

Two launcher activities on android tv

Is it possible to have multiple launcher activities on android tv like on mobile android? I've tried to declare two activities with intent filters like this:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
</intent-filter>
but it doesn't work. I see two icons but they launch the same activity. Thanks in advance!

single app with different launches to configure and run in android

I have a requirement to do an app to function like this.
Its an android application and it should have 2 launching methods.
One is to proceed the function directly when touching the icon.
Another icon should be there to give the setting to the same app to set the setting the settings of the android application.
Basically the app should work like the screen off and lock app in the market.
How can i achieve these 2 things in one app? When i install the app, i need to have two icons, one to do the functionality directly and other to set the settings of the application.
I believe you are trying to have to separate launchers (icons to start apps) in your app, launching two different activities. This is easily achieved within your manifest. Create two activities, say MainActivity and SettingsActivity and then declare them in manifest as launch-able - with different titles:
<activity
android:name=".MainActivity"
android:label="#string/main_activity_title"
android:icon="#drawable/main_icon">
<intent-filter android:label="#string/main_app_title">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SettingsActivity"
android:label="#string/settings_activity_title"
android:icon="#drawable/settings_icon">
<intent-filter android:label="#string/settings_app_title">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
When your app is installed, there will be two icons created: one to start the MainAcivity and another one to start SettingsActivity.

Android Activity Intent Filter, Action View and Category Default

I was looking at sample android applications, and I noticed all of the activities in the manifest had:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
I noticed that my activities start fine without this intent-filter. So what is the point of this intent-filter and is it best to include them?
<intent-filter> has to be given for atleast the first activity which you want to start in your application.
The lines :
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
if given to an activity, then its purpose is to enable the user to interact with the activity that is either VIEW or EDIT or INSERT.
DEFAULT category is required for all filters except for those with MAIN action and LAUNCHER category
It is not necessary to give the <intent-filter> to every activity, but as said in the developer's guide it would be a better practice to use.

In android every .java file becomes an app on the phone!

I have 6 .java files under one package.In eclipse, after I export the .apk and install the app on the phone or if i run the app on the emulator, there are 6 applications created, one for each .java file! The java files are different screens in my app.So i can open any java file by clicking on the icon in the menu.I only want one of them to be openable through the icon in the menu. So basically, only one icon should be seen in the main menu, which upon clicking opens the first activity in the manifest file!
Any idea whats wrong?
Thanks.
My assumption:
You registered all your Activities in the AndroidManifest (which is right) but as intent-filter you always used
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
That intent-filter tells Android to add the Activity to the launcher. Remove those Intent-filters (except one Activity that's going to be your main entry point) and it should work.
What does your manifest say? It might specify that all activities are shown as seperate apps...
Just check your AndroidManifest.xml file and modify your activity same as below code example:
<activity android:name=".MainActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".SecondActivity"
android:label="SecondActivity">
</activity>
So if you mark the above code then you can easily come to know that the below code mention that this activity is going to be act as a launcher activity.
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Try to mention the intent-filter action as MAIN and Category as Launcher only for your entry activity in your app.
<intent-filter>
<action android:name="android.intent.action.MAIN"></action>
<category android:name="android.intent.category.LAUNCHER"></category>
</intent-filter>.
Remove this for all other activities except the entry point for your app.
Hope this helps.

Categories

Resources