I have pasted the code of my Androidmanifest.xml,how does android decides which activity to launch when application starts ? In this case its the mainactivity. What changes to I need to make if I want to launch AnotherActivity when application launches?
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.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="com.example.AnotherActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
The MAIN element specifies that this is the "main" entry point to the application. The LAUNCHER element specifies that this activity should be listed in the system's application launcher (to allow users to launch this activity).
<activity
android:name="com.example.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>
Just remove the intent filter from the next activity!!
When the user selects your app icon from the Home screen, the system calls the onCreate() method for the Activity in your app that you've declared to be the "launcher" (or "main") activity. This is the activity that serves as the main entry point to your app's user interface.
You can define which activity to use as the main activity in the Android manifest file, AndroidManifest.xml, which is at the root of your project directory.
The main activity for your app must be declared in the manifest with an that includes the MAIN action and LAUNCHER category. For 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>
Based on this, we can conclude that you currently have a faulty configuration. Only one activity can have the Intent filter for Main (so you should remove the <intent-filter> from your .MainActivity if you want to use AnotherActivity as you "Home" Activity).
<activity
android:name="com.example.AnotherActivity"
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="MainActivity" ></activity>
As stated in our conversation, you want to show a determinate action at launch, with is own functions and layout. The solution is to use one Activity which inflate Fragment1 or Fragment2, based on your condition.
Dealing with Fragment is very difficult, but when you will master them, you will have fun. There are few example on the net about Fragment, but i tell you this: read and practice is the only way you will learn something. Copy and paste from other source code / example will not help you. Follow this links:
link 1
link 2 with sample
link 3 for supporting tablets
Good luck!
I am trying to use Implicit intent to launch an activity within the same application and for an activity of another application(my other application, not the native one), but couldn't succeed in any of the cases.
Here is my sample code for the first part (i.e. to launch an activity within the same application):
Inside Activity TESTActivity
Intent intent = new Intent();
intent.setAction("com.myapp.game.myimplicit_action");
startActivity(intent);
and here is my manifest file declaration for some activity say 'ImplicitActivity' with the same action:
<activity
android:name=".TESTActivity"
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=".ImplicitActivity">
<intent-filter>
<action android:name="com.myapp.test.myimplicit_action" />
</intent-filter>
</activity>
Both the activities TESTActivity and ImplicitActivity are in the same application under same package. Still my ImplicitActivity activity is not getting called.
I have figured out the problem. Posting the answer for the others facing the same problem.
We need to add Default Category in order to make Implicit intents work. So here is the correct manifest entry for the same activity :
<activity
android:name=".TESTActivity"
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=".ImplicitActivity">
<intent-filter>
<action android:name="com.myapp.test.myimplicit_action" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
I keep getting "ActivityNotFoundException: Unable to find explicit activity class ... " when using Eclipse's emulator to call the activity of another application from an application. Perhaps the problem maybe related to I am not able to download to/find both applications at the same time when I click on "Manage Applications" in Settings. This is the first project I need to call the activity of another application. But I am not sure the code is correct either. Please help me determine if there are errors in the code snippets I present below. It is hinted that I can set the action field of the intent to achieve the objective but have not found learning material for this. I learned about using the setComponent method in the calling app and to add android:export to the called activity's AndroidManifest.xml. Thanks in advance!
Calling app's relevant source code:
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.MyPackage", om.MyPackage.Activity1));
startActivity(intent);
Calling app's relevant AndroidManifest.xml :
<application android:icon="#drawable/icon" android:label="#string/app_name">
<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=".Activity1">
<intent-filter>
<action android:name="com.MyPackage.Activity1" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
Relevant code of AndroidManifest.xml of the activity of another application
<activity android:name=".Activity1" android:exported = "true">
<intent-filter>
<action android:name="com.MyPackage.Activity1" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Firstly point out that you're trying to start Activity in Application2 from Activity in Application1
You have to give them separate namespaces
both applications now have com.MyPackage.* prefix
OR use names Activity1 and Activity2
So you will have
com.MyPackage1.Activity1
// and
com.MyPackage2.Activity1
Then you can use this code, to start Activity1 in MyPackage2 from MyPackage1.
// in file com.MyPackage1.Activity1
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.MyPackage2", "com.MyPackage2.Activity1"));
startActivity(intent);
And your AndroidManifest.xml files should look like this:
first
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name="com.MyPackage1.Activity1"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
second
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name="com.MyPackage2.Activity1"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
see related SO question:
How to start activity in another application?
I am writing a simple program of Android, and getting these no errors, I don't know what they are. My program is right, but showing not output.
I think it is because of these two lines:
[2005-01-06 19:56:38 - my_Android] No Launcher activity found!
[2005-01-06 19:56:38 - my_Android] The launch will only sync the application package on the device!
Here's an example from AndroidManifest.xml. You need to specify the MAIN and LAUNCHER in the intent filter for the activity you want to start on launch
<application android:label="#string/app_name" android:icon="#drawable/icon">
<activity android:name="ExampleActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Multiple action tags in a single intent-filter tag will also cause the same error.
Like Gusdor said above, "Multiple action tags in a single intent-filter tag will also cause the same error." (Give him the credit! I could just kiss Gusdor for this!)
I didn't find any docs for this fact!
I had added a new (USB) action and being clever, I lumped it in the same intent-filter. And it broke the launch.
Like Gusdor said, one intent filter, one action!
Apparently each action should go in its own intent filter.
It should look like this...
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
</intent-filter>
When I did this, WAZOO! it worked!
Do you have an activity set up the be the launched activity when the application starts?
This is done in your Manifest.xml file, something like:
<activity android:name=".Main" android:label="#string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Check your manifest.xml. Make sure you have the category LAUNCHER there.
<activity android:name=".myActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
It means you didn't specify an Activity for Android to launch as the default when the app opens from the launcher. You have to add an Intent Filter in the Manifest for the Activity you would like to act as the default when the app is being launched.
Read http://developer.android.com/guide/topics/intents/intents-filters.html#ccases for more details.
I fixed the problem by adding activity block in the application tag. I created the project using wizard, I don't know why my AdroidManifest.xml file was not containing application block? I added the application block:
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".ToDoListActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
And I get the desired output on the emulator.
As has been pointed out, this error is likely caused by a missing or incorrect intent-filter.
I would just like to add that this error also shows up if you set android:exported="false" on your launcher activity (in the manifest).
I had this same problem and it turns out I had a '\' instead of a '/' in the xml tag. It still gave the same error but just due to a syntax problem.
If you are using the standard eclipse IDE provided by google for Android development, you can check the "Launcher Activity" check-box while creating a new Activity. Please find below:
In Eclipse when can do this:
But it is preferable make the corresponding changes inside the Android manifest file.
You missed in specifying the intent filter elements in your manifest file.Manifest file is:
<application android:label="#string/app_name" android:icon="#drawable/icon">
<activity android:name="Your Activity Name"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Add and check this correctly. Hope this will help..
Manifest is case sensitive, so please compare this lines for any case mismatch especially the word MAIN in:
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
You can add launcher to activity in eclipse manifest visual editor:
MAIN will decide the first activity that will used when the application will start.
Launcher will add application in the application dashboard.
If you have them already and you are still getting the error message but maybe its because you might be using more than more category or action in an intent-filter. In an intent filter there can only be one such tag. To add another category, put it in another intent filter, like the following
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!--
TODO - Add necessary intent filter information so that this
Activity will accept Intents with the
action "android.intent.action.VIEW" and with an "http"
schemed URL
-->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="http" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
just add this to your aplication tag in AndroidManifest.xml file
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
and also edit the uses-sdk tag from android:targetSdkVersion="16" to 17
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
You have not included Launcher intent filter in activity you want to appear first, so it does not know which activity to start when application launches, for this tell the system by including launcher filter intent in manifest.xml
I am confirming about creating activity.
My Manifest.xml is like this :
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".FirstActivity"
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="#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=".ThirdActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
You can see property action android:name= property is "android.intent.action.MAIN" and
category android:name= is "android.intent.category.LAUNCHER" for all activities.
When the application starts up, it calls FirstActivity.
Then calls useless Activity such as ThirdActivity or SecondActivity.
In this case, is my manifest.xml correct?
Or, do I need to set another property to Second and Third activity?
If so, what is that?
I wonder manifest.xml file is right for my case.
Please advise.
Try this config:
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".FirstActivity" 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="#string/app_name">
<intent-filter>
</intent-filter>
</activity>
<activity android:name=".ThirdActivity" android:label="#string/app_name">
<intent-filter>
</intent-filter>
</activity>
Think of an Intent as message used to start an Activity to do something. So I can create an Intent to view a web page and an application with an Activity which knows how to view a web page - most likely the browser - can intercept his Intent as act on it.
You tell Android which Activities can act on which Intents using the <intent-filter> part of your Manifest.
The MAIN Intent is a special one. This is sent to an application when it is launched and basically it says "Go!" So the Activity which shoud be displayed first needs to intercept this by having a correctly defined <intent-filter>.
As you had all three Activities with MAIN in their filter they all responded to the request to start your application. So you should have that <intent-filter> only for FirstActivity.
One of the other problems with using
<category android:name="android.intent.category.LAUNCHER" /> for more than one activity is that the Phone's launcher menu will display more than one icon...
From the docs:
CATEGORY_LAUNCHER The activity can
be the initial activity of a task and
is listed in the top-level application
launcher.