Manifest file structured in android studio for different activities - android

I want to know how to set multiple activities by using different layouts and through intent filters
How to set pages in application and what we have to specify in section of activity in manifest file for action and category for different pages of activity.
Please help me on that. What should I follow, So that I can make proper flow of my application.
Any suggestion or references for the same would be appreciated.

Mainifest.xml is having more information about application.
Activity defining is also one part of Manifest.xml, So define all the activities which are used in your app flow here. Main launcher activity will have tag with action - MAIN and category type - LAUNCHER. And other activities are defined in a simple manner.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example">
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.LauncherActivity"
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.ActivityA" >
</activity>
<activity android:name="com.example.ActivityB" >
</activity>
....
</application>
There are several other attributes that you can include in this element, to define properties such as the label for the activity, an icon for the activity, or a theme to style the activity's UI.
Follow for more: Activity
Labels in Activity: Activity labels in Manifest.xml

Related

Android: declaring particular activity as the launcher activity

I am just starting with android and trying to alter my android manifext .xml file such that a particular activity is launched first. My code is as follows:
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".CrimeListActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".CrimeActivity">
</activity>
</application>
I have a CrimeListActivity java class which simply should display an empty activity. However, it continues to default to displaying the activity that was specified in the manifest originally. ( In this case, .CrimeActivity.
It's hard to be more specific without posting too much code so I'm hoping someone could give me a couple pointers on where to start poking around when issues like this arise.
Thanks!

How to insert an android activity into the manifest given in a tutorial?

I am very new to android development with eclipse, and I encounter dozen of errors and problems. Here is the next one:
I am following an android tutorial given here in order to set up the action bar. In this tutorial is says to insert an activity as follows:
<activity android:theme="#style/Theme.AppCompat.Light" ... >
Can I just put this line into the xml manifest file?
<activity android:theme="#style/Theme.AppCompat.Light">
Or do I need to replace the '...' by something more useful?
Please read the docs: activity-element
The activity's name is required, so you would need to have:
<activity android:theme="#style/Theme.AppCompat.Light" android:name="MyActivity">
Other than that, you are not required to add any other attributes.
Although be sure to place the activity element within the proper place in your xml. It should be contained in your application block:
<application android:label="#string/app_name"
android:icon="#drawable/ic_launcher"
android:theme="#android:style/Theme.Holo.Light">
<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>
</application>
Unless you really want your app to work under API levels under 3.0 then you have to add it like this.
android:theme="#style/Theme.AppCompat.Light"
Inside your already defined activity in your manifest (the one that has the intent filter and other declarations).
otherwise you dont have to add that at all.
This is one example.
<activity
android:name=".MainActivity"
android:theme="#style/Theme.AppCompat.Light"
android:screenOrientation="portrait"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
and this is another
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme=#style/Theme.AppCompat.Light"" >
<activity android:name=".DetailActivity"
android:label="#string/app_name" >
</activity>
The second way you posted is just fine, be sure to close the activity tag so it looks like <activity android:theme="#style/Theme.AppCompat.Light"></activity>
Also, if you're using eclipse, it is easier to go into the AndroidManifest and under the Application tab scroll to the bottom where there's Application Nodes and then add your view from there. Eclipse will auto generate the correct code in the xml file.

Setting Application Name in Android Devices

I implemented a android project named 'vignesh', in which i had source package as com.example.learn.android. In my tab while uninstalling the app, its showing com.example.learn instead of project name alone. Please advice..
You can specify your application label in the AndroidManifest.xml
<application
android:label="#string/app_name"
...>
</application>
In the above example you have to define app_name in res/strings.xml
<string name="app_name">My app name</string>
If this is not working in the AndroidManifest.xml file:
<application
android:label="#string/app_name"
...>
</application>
Look for the startup activity(the activity with the android.intent.action.MAIN & android.intent.category.LAUNCHER), example:
<activity
android:name=".SplashScreen"
android:label="com.example.learn"
android:noHistory="true"
android:screenOrientation="landscape"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
You probably have the android:label mentioned just like the example above. The strange thing is that Android takes your first activity's name (label) as app name (I don't know why).
If you just remove (or rename) the android:label="com.example.learn" line it should be ok. Removing the line ensures that the app will look for the android:label tag defined in the <application> part of the AndroidManifest.xml file.

Reorganizing activities in different folders

I want to change the structure of my android application to have the activites in a subfolder called activities. So, my code structure will become
com.example.myapp.activities.MainActivity
and all the activities will reside within com.example.myapp.activities
How do I achieve this ? Also, What changes will have to be made in the manifest for this to work ? How will I access other activity classes from within other activities ?
<activity
android:name=".activities.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>
EDIT : I achieved this using dragging and dropping the activities in the folders but now I am getting this error on setContentView(R.layout.main); : main cannot be resolved or is not a
field
If you organize all activities in same packages, then you have to define the activity without package declaration in Manifest file, example
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp.activities"
android:versionCode="1"
android:versionName="1.0" >
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:name=".WorldClockApplication"
<activity
android:name=".WorldClockHomeActivity"
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=".AddLocationActivity"/>
<activity android:name=".EditPreference"/>
</application>
</manifest>
Then you should call that activity inside another activity using intent. Consider I'm calling WorldClockHomeActivity from WorldClockApplication activity as follows:
Intent myIntent=new Intent(WorldClockApplication.this,WorldClockHomeActivity.class);
startActivity(myIntent);
Then do clean, refresh your project you wont get error in your project. If get error on
setContentView(R.layout.main);
that means you have problem in res/strings or res/layout or res/drawable folders not in manifest file
If you are using Eclipse create a new packet in your project and drag and drop your activities files in there. Eclipse will take care of all the necessary changes.
The changes are in your directory structure and in the manifest as you have posted in the question.
Activities can be launched (or new Intents can be sent to them) as usual through Intent(context, YourActivity.class);
I wouldn't move the activities though, rather I'd organize other Java classes in separate packages.

How to name Android Application

I have an Android App with 2 activities. I have the following in the AndroidManifest:
<application android:icon="#drawable/icon" android:label="#string/app_name" android:debuggable="false">
<activity android:name=".MyCellTracker" android:label="#string/activity1_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".DisplaySuccess" android:label="#string/activity2_name"></activity>
The activities are properly named, yet the application is using the project name rather than the android:label (#string/app_name) I have given it. If I go to delete the application, then I see that it is named using the android:label. Why is the name that is displayed under the icon on the program launcher not using android:label in the application node?
This may not be the answer you're looking for, but you can set the activity title using setTitle(string title).
Set the title programmatically, and set the app title in the manifest.xml using the main activity's label.
According to that reference:
http://developer.android.com/guide/topics/manifest/activity-element.html#label
it is the label of the main activity. However if you don't set a label in the activity, the label of the application is taken.

Categories

Resources