I have created a custom launcher and its perfectly working fine.Now i want to add an activity to it which shall be launched like any other app from launcher.
Here is my Manifest file.
<activity
android:name="com.sample.launcher2.Launcher"
android:launchMode="singleTask"
android:clearTaskOnLaunch="true"
android:stateNotNeeded="true"
android:resumeWhilePausing="true"
android:theme="#style/Theme"
android:windowSoftInputMode="adjustPan"
android:screenOrientation="nosensor">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.MONKEY"/>
</intent-filter>
</activity>
<activity
android:name="com.sample.launcher2.MainActivity"
android:label="#string/application_name"
android:icon="#mipmap/ic_launcher_home">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
I am not able to launch activity from launcher.How can i achieve it ?
Make following changes hope it will work
<activity
android:name="com.sample.launcher2.Launcher"
android:launchMode="singleTask"
android:clearTaskOnLaunch="true"
android:stateNotNeeded="true"
android:resumeWhilePausing="true"
android:theme="#style/Theme"
android:windowSoftInputMode="adjustPan"
android:screenOrientation="nosensor">
<intent-filter>
<action android:name="com.sample.launcher2.Launcher" />//Here the change
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.MONKEY"/>
</intent-filter>
</activity>
<activity
android:name="com.sample.launcher2.MainActivity"
android:label="#string/application_name"
android:icon="#mipmap/ic_launcher_home">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.HOME"/>
</intent-filter>
</activity>
Changing that activity's launch mode to singleTask may help!
Related
I have in my AndroidManifest.xml two activities that I could launch
<activity android:name=".ExperimentActivity"
android:label="Experiment">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity"
android:label="Main">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
When I install, there's two icons, Main and Experiment. However, when I launch, both also launch the ExperimentActivity.
Did I miss anything?
Please add the exact package like
android:taskAffinity="com.yourpackage.MainActivity"
and
android:taskAffinity="com.yourpackage.ExperimentActivity"
to your activity tag .
Hope this helps.....
So, normally you only launch the Main Activity, which is declared as your launcher in the manifest. All other activities then get launched from the Main Activity.
You should only declare one Launcher Activity in your manifest.
E.g.:
<activity android:name=".ExperimentActivity"
android:label="Experiment">
<intent-filter>
<!-- declare your own filters if you need them -->
<!-- for example parent activities -->
</intent-filter>
</activity>
<activity android:name=".MainActivity"
android:label="Main">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
I found another way of doing so, which is to add the following to my ExperimentActivity scope.
android:launchMode="singleInstance"
i.e.
<activity android:name=".ExperimentActivity"
android:launchMode="singleInstance"
android:label="Experiment">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity"
android:label="Main">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
I have an Activity that is both the MainActivity and the activity that should be started when the 'Share'-Button within the Gallery is clicked.
So my Manifest looks like this:
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.SEND" />
</intent-filter>
</activity>
With the above manifest, by app appears within the share menu but not in the app drawer. If I remove the line that sets the mimeType the app appears in the app drawer but not within the share menu in the gallery.
Any suggestions how to achieve both?
Thanks in advance.
Use two separate <intent-filter> elements in the <activity>: one for MAIN/LAUNCHER, the other for SEND/DEFAULT/MIME type.
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.MAIN" />
</intent-filter>
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
<action android:name="android.intent.action.SEND" />
</intent-filter>
</activity>
Like this: (This is broke)
<activity
android:name="com.example.Main"
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="com.example.IKI"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.MAINIKI" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.UC"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.MAINUC" />
<category android:name="android.intent.category.**DEFAULT**" />
</intent-filter>
</activity>
Problem is the bold code. How can i use that activity? What is other categories that are choosable? Is there? What should i do?
you may use different activity when you have more than one main activity class in your project.
All
I want to set two action in launcher activity in manifest as like below, So it's possible.
<activity
android:name=".MainActivity"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="com.example.sampleapp.android.widget.buttons.ButtonWidget.ACTION_WIDGET_CONFIGURE"/>
</intent-filter>
</activity>
Is it possible?
Try to define action with multiple intent-filter
<activity
android:name=".MainActivity"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="com.example.sampleapp.android.widget.buttons.ButtonWidget.ACTION_WIDGET_CONFIGURE"/>
</intent-filter>
</activity>
check this post Default when using multiple Actions in Intent-Filter
I'm working on an Android app using Eclipse and just started noticing a weird glitch.
When I deploy the app to my phone for some reason multiple app icons appear in my "Apps" folder area. Each icon brings me to a different class page within my app when tapped. Has anyone else experienced this as well?
Here's a screenshot of the issue when running the app from the emulator on my laptop.
Since the issue is appearing in the emulator I know that it isn't my phone that's causing the error.
Each of the icons you see in that screenshot represents a different activity in my manifest file.
Here's how the activity is set up in my manifest.
<activity android:name=".MainJava">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".AppClass">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Would you say that this error being caused because of the way that I am setting up the activities? If so, how would you suggest that I edit the activities to fix this problem?
I've never seen this in any of the apps I've built before this one.
Only MainActivity(Launcher Activity) have intent filter with action as Main and category as Launcher,
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
And Remove this Two line For other Activity.
Change from:
<activity android:name=".MainJava">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".AppClass">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
To:
<activity android:name=".MainJava">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".AppClass">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
There should be only one MAIN and one LAUNCHER