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!
Related
I'm new to android and Developing very basic App. I have completed my development but when ever I debug my app in device. It shows 2 icon. I'm facing this problem after implementing Splash Screen in my app. Please suggest me how to overcome. My manifest
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="#mipmap/icc"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".SplashScreen"
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=".Login_page">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
In your manifest file -
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
This piece of code means which activity will first start when you launch the app. But you have put this code in both of your activities hence Android provides a separate launcher for both the activities and you see two icons.
So remove the above code from one of the activities. Just let it remain in the Activity you want to start first when your app launches.
TO have a icon on the launcher screen you need action of the activity to be action_main and category to be launcher and your both activity qualifies the criteria for this.
You should change your login_activity category to default or simply remove the category.
You can start your login activity from splash activity.
I hope it helps you.
I just created my first Android app, all works fine, but all of the activities are shown on my Android menu. What did I do wrong?
Screenshot: imgur.com/9CmXU
I want to have one icon, directing to MainActivity, not all activities
<!-- language-all: lang-html -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myApps.birthdaymeter"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="#drawable/my_logo"
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=".BirthdayMeter"
android:label="#string/title_activity_birthday_meter" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".AboutWindow"
android:label="#string/title_activity_about_window" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ShowResult"
android:label="#string/title_activity_show_result" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
This is my manifest, changing logo didn't help
The <intent-filter> tag is used to describe the type of Intents that each Activity will respond to. The "android.intent.action.MAIN" action says that this Activity is an entrance point for your Application (think the main method that a java program requires). The "android.intent.category.LAUNCHER" category tells the OS to display the Activity in your list of Applications. Adding the DEFAULT category is ok, but effectively the same as omitting the <intent-filter> tag completely (which I find to make for much cleaner and easier to read code). You should only be using the <intent-filter> tag with these two actions and categories on the Activity that starts when a user opens your app. If wanted an Activity within your application to be able to respond to some special intents, you would use the tag to define which it responds to.
Here's a link to the google dev pages to help you learn more about Intent Filters.
http://developer.android.com/guide/components/intents-filters.html
Here's the documentation for the <intent-filter> tag. It's not the easiest to understand though.
http://developer.android.com/guide/topics/manifest/intent-filter-element.html
And here's the docs for the Manifest file and the Intent class. Both of these are good for reference if you're not sure about which tags to use in your Manifest. Good luck!
http://developer.android.com/guide/topics/manifest/manifest-intro.html
http://developer.android.com/reference/android/content/Intent.html
You phrased your question extremely generally, so I am not sure what to answer. It seems like you haven't called nameOfActivity.this.finish() when you launched another activity
If you post your manifest file I can help a little more, but it looks to me like you have not declared your activities correctly.
It should be setup somewhat like this:
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name="Activity1"></activity>
<activity android:name="Activity2"></activity>
<activity android:name="Activity3"></activity>
</application>
Essentially, create an application declaration, and then include each activity within it.
I have an android application with three activities: Loading, Main, Credits.
But when I try to run and look into the emulator, I have three icons: Loading, Main, Credits.
How can I just have a single Application name? And where do I set it?
Set in android manifest file in application level.
android:label="#string/app_name"
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".Loading"
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=".Main" />
<activity android:name=".Credits" />
In your AndroidManifest.xml, you just need to set <intent-filter> for only one Activity other Activities don't need this tag.
I have two activities namely login and calendar in my Application. Currently my startup activity is "calendar". I want to run the login as first activity not calendar.
The startup activity [Launcher Activity] is declared in the projects' AndroidManifest.xml file
Look for that activity tag in the manifest which looks like this
<activity android:name=".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>
Look at the attribute android:name. Main is the class which is launched when the app starts. Currently your calendar activity name should be there. Change that to the .classpath of your activity that you want to launch.
That should do it. You may also want to do the hello world application in the tutorials and go through the docs a little to see how Android Applications work.
Add Intent filter to the Activity in which you want startup.
In your case Modify the AndroidManifest.xml file as follows
<activity android:name=".login"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
remove the intent-filter code from calendar Activity tag in manifest and add it to the Activity you wanna load first
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
I mean paste it in the activity you like to run as default.
<activity
android:name="com.example.gridviewimages.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>
Where as
From the docs
category -- Gives additional information about the action to execute. For example,
CATEGORY_LAUNCHER means it should appear in the Launcher as a top-level application, while
CATEGORY_ALTERNATIVE means it should be included in a list of alternative actions the user can
perform on a piece of data.
MAIN means that this activity is the entry point of the application, i.e. when you launch the application, this activity is created.
You want the Application element of the Android Manifest file. You can see details here.
Look at the name attribute, this points to the Application class.
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.