I am trying to go back to a previous activity using intents.
The problem I have is with my main page, it is the page that launches the app so when I try to put the name android.intent.action.MAIN as my intent, it gives me the option to open all the apps.
What should I do to fix this? How can I rename my activity name?
Thanks
Here is my Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.AssaultAlarm.full" android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="5" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.READ_CONTACTS" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".AssaultAlarmActivity"
android:screenOrientation="portrait" android:theme="#android:style/Theme.NoTitleBar"
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=".Info" android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar" android:label="#string/app_name">
<intent-filter>
<action android:name="com.AssaultAlarm.INFO" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".Settings" android:screenOrientation="portrait" android:permission="android.permission.READ_CONTACTS"
android:theme="#android:style/Theme.NoTitleBar" android:label="#string/app_name">
<intent-filter>
<action android:name="com.AssaultAlarm.SETTINGS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
This is how I want to call it
Intent info = new Intent("AssaultAlarmActivity.class");
startActivity(info);
If you want to go to previous activity you can just finish current activity. You will automatically go to previous activity in stack but if you want to go specific activity you can use following.
Why you are not using explicit intent.
Intent info = new Intent(CallingActivity.this,AssaultAlarmActivity.class);
startActivity(info);
If you don't want to use explicit intent you may add new intent filter for your activity
<activity android:name=".AssaultAlarmActivity"
android:screenOrientation="portrait" android:theme="#android:style/Theme.NoTitleBar"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="MyAction" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
and
Intent info = new Intent("MyAction");
startActivity(info);
If you want to rename your activity you will do it as follow
<activity-alias android:name="AlternateName"
android:targetActivity=".AssaultAlarmActivity"
/>
Related
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
I have some intents to execute different activities, my problem is that when I run the app in the device, eclipse install it with the name of the last activity. For example:
We have, three activities: 1 - 2 - 3. The first is the main activity (1), it name is Noow but I have an Intent to another activity (3) to get the location and return the data to (1). The app installed is named as getLocation (3) and it must have the name of the (1).
This is the manifiest xml file. Could someone help me with this? Thanks
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="victor.martin.noow"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="victor.martin.noow.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="victor.martin.noow.LoginScreen"
android:label="#string/title_activity_login_screen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="victor.martin.noow.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="victor.martin.noow.getLocationActivity"
android:label="#string/getLocationActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
This is happening because the SDK will use the name of the activity having the LAUNCHER property:
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
The simplest solution would be to delete the LoginScreenActivity label and set it programatically. In this case the label provided in the tag will be used.
First of all there has to be one activity set as main activity i.e launcher activity. What you have done is set all activities as main which is incorrect in all terms of programming logic.
The activity with
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
gets the by default name, and by convention in your case after reading your xml the last activity got default name.
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.
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.
I am creating an application which will call a new transparent activity to launch every 5 minutes.whether the phone is locked or not.
Every thing is working fine.But the problem is when this activity is started,it will start on
a MAIN Launcher activity.
I want to show that activity on Desktop, menu or whatever user is in.
How can i do this?
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.spec.test"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".BroadCastDemoActivity"
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=".TransparentActivity"
android:label="Transparent"
android:theme="#style/YourTheme">
</activity>
<receiver android:name="MyBroadCastReceiver"></receiver>
<service android:name="MyService"></service>
</application>
<uses-permission android:name="android.permission.VIBRATE"></uses-permission>
<uses-permission android:name="DEVICE_POWER"></uses-permission>
<uses-permission android:name="android.permission.WAKE_LOCK" />
</manifest>
You TransparentActivity needs an <intent-filter> change your TransparentActivity part in the manifest to this
<activity android:name=".TransparentActivity"
android:label="Transparent"
android:theme="#style/YourTheme">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Or to this if you want the transparent activity to start when you start the application from the users homescreen.
<activity android:name=".TransparentActivity"
android:label="Transparent"
android:theme="#style/YourTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>