Every activity can use "android.intent.action.MAIN"? - android

aid with this example at Return back to MainActivity from another activity
I copy that codes as follow,
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="15" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Activity1"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.ACTIVITY001" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Activity2"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.ACTIVITY002" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Activity3"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.ACTIVITY003" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
So many statements: action android:name="android.intent.action.MAIN"; if I would use their class path to instead of them, they can also do the job. what's different from these two ways?

setClass() is a explicit declaration, setAction() is a implicit declaration. It will find your target action im manifest.xml.
If the intent-filter with “android.intent.action.MAIN”, there would more entryance of your application, also you can found more icon in launcher.

its wrong
<action android:name="ACTIVITYNAME FOR INTENT" />
<category android:name=""/> // android.intent.action.DEFAULT or android.intent.action.MAIN
android.intent.action.MAIN is given to the activity wich is going to launch at first and
android.intent.action.OTHER to the rest of the activities getting called by other activities
Your application will refer to the manifest to fetch the activity for first launch , havin MAIN in it

Related

My app icon does not appear in the emulator home screen

I want specific ordered reasons why my app icon does not appear, I can run it on the emulator yet and I need to know what's wrong with my app? I'm a beginner my code is so simple, though I can't find why is this happening.
Here is my manifest:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".Splash"
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=".MyActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="com.example.hp.app2.MyActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
Instead of
<category android:name="android.intent.category.launcher" />
it must be
<category android:name="android.intent.category.LAUNCHER" />

Keep Getting ActivityNotFoundException

As the title says I keep getting this error and don't know what I'm missing. I've cleaned the project several times. Here is my code:
startActivity(new Intent(this, UsrPrefs.class));
In the manifest:
<application
android:label="#string/app_name" >
<activity
android:name=".IcyArmActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:label="#string/app_name"
android:name=".UserPreferences"
android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.PREFS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
OHHHHHHHHHHHHHHHHHHHH!!!!! Thanks you guys. I thought the UsrPrefs.class was the name of the class so that is what I was using. I see the connection now. DOH!!!!
It's because you defined a class as an activity with one name and starting the other activity which is not registered with that name in the manifest.xml
Replace this:
<activity
android:label="#string/app_name"
android:name=".UserPreferences"
android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.PREFS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
with
<activity
android:label="#string/app_name"
android:name=".UsrPrefs"
android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.PREFS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
In your menifest the name of activity is UserPreferences.So edit like this
startActivity(new Intent(this, UserPreferences.class));
Use
startActivity(new Intent(IcyArmActivity.this, UserPreferences.class));
for starting new Activity from main Activity because you have declared UsrPrefs as UserPreferences in manifest
OR
you can declare UsrPrefs as new Activity in manifest as :
<activity android:name=".UsrPrefs" />

App is installed and has two icons

I made a android app and it worked very well, but there are two icons in my device screen. I think it could be a AndroidManifest problem. Any idea what it could be?
This my AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="pk.aeh.ideos.taa"
android:versionCode="1"
android:versionName="1.0" >
<application
android:icon="#drawable/icon"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar" >
<activity
android:name=".Ghinho_congviecActivity"
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="Nhap_congviecActivity"></activity>
<activity android:name="Sua_congviecActivity"></activity>
<activity
android:name=".Quizzes"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".PlayGame" />
<activity android:name=".Result" />
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
This could be because you have declared two activities as MAIN and LAUNCHER
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
in your Androidmanifest.xml file. You need to have only one activity with these intent filters so that when the app is installed the system will know which activity is to be used as the main launcher activity.
It is. You have two of these:
<category android:name="android.intent.category.LAUNCHER" />
Get rid of the one you don't want.
You need to make these changes to your Manifest.xml
<activity
android:name=".Ghinho_congviecActivity"
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="Nhap_congviecActivity"></activity>
<activity android:name="Sua_congviecActivity"></activity>
<activity
android:name=".Quizzes"
android:launchMode="singleTask">
</activity>
I am assuming that the Activity with the attribute android:label="#string/app_name" might be your main activity.
It could be because you have changed your package name and installed it twice with different package names.
Remove the intent filter of one the activity and it would work perfectly.!
Your manifest file should only have one activity with below Intent Filter, Activity which you want to have an icon:
<intent-filter>
<action android:name = "android.intent.action.MAIN" />
<category android:name = "android.intent.category.LAUNCHER" />
</intent-filter>
Based on your description, it sounds like two activities have this line. Check your Manifest...
You can declare only one Intent filter in the activity, on AndroidManifest.
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
If you used two or more intent filter in AndroidManifest, then you will have display 2 app icon, So remove it & set one intent filter.
I hove this is usedful to you.

How can you know what the main launch Activity is?

Newb question. How can you know what the main launch Activity is? Learning Android.
Assuming this is for your code, check out the manifest.xml and look for this element:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
It should be contained within <Activity> ... </Activity> tags, and that Activity is the one that a user can launch from their phone.
You have to put the right intent tag on the activity in the manifest:
<activity android:name=".SomeActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
The main activity can be considered the one which handles the initial screen of the application you're creating.
?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="clustering.android"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10"
android:targetSdkVersion="11" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application
android:icon="#drawable/gene_launcher"
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=".yourSubActivity" android:label="#string/<ActivityName>"> </activity>
...list of other activities...
</application>
</manifest>
The main activity can be found and set in AndroidManifest.xml; look for
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
The <activity> with that action is the main activity (is the entry point for the app).
You can look into AndroidManifest.xml in your porject
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
This will help you to find Launch activity.

How to specify which activity starts on app launch?

I have an app with 3 different activities in it. When I launch the app one of the activities always starts first. But I want a differnt activity to start before the one that is currnetly starting first.
How would I change this to make a differnet activity start first?
Open your AnroidManifest.xml file and set the Launching Activity using the intent-filter tag as follows,
<activity android:name=".LaunchingActivity"
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 need to add an intent filter to the activity you want to start on application launch in your app's AndroidManifest.xml:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
You need to make changes in AndroidManifest.xml file...
<application
android:icon="#drawable/image"
android:label="#string/app_name" >
<activity
android:label="#string/app_name"
android:name="define the activity which you want to start first here" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".FirstActivity" >
</activity>
<activity android:name=".SecondActivity" >
</activity>
<activity android:name=".ThirdActivity" >
</activity>
</application>
Hope this will help you....
In your AndroidManifest.xml put the following:
<activity android:label="#string/app_name"
android:name=".TestActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
The intent-filter inside the activity tells Android which Activity to launch.

Categories

Resources