Starting an Activity First in Android? - android

I'm having an issue starting activities in order, and I don't know if it is an issue in the manifest or in the code. I tested this code a while ago when it was working, but now it's not.
The first activity links to the second, which links to the third. I listed the first activity first in the manifest. However, when I start my emulator, it's the second activity that runs first. I am very confused. Here is my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="hmdywifinal.com"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="15" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".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>
<activity android:name=".Activity2"
android:label="Startpage">
</activity>
<activity android:name=".Activity3"
android:label="Activity3"></activity>
</application>
Do you think something is wrong with it?

Make sure you are running your program from Activity1 and not from Activity2.
If you run it from Activity2 it will skip Activity1 even though you have your manifest set like you described above.

Order in which Manifest file declares Activities has nothing to do with the runtime order.
First Activity gets launched from a Launcher ( which is Activity1 in your case )
I am assuming you are launching Activity2 and 3 using Intents in your code. So you are in control on the way these activities get launched.

Refer to the api Demos, Which has got a similar application Proof Of Concept. It will give you a better idea on mving from one application to other.

Related

Android Application sometimes starts the wrong activity

I'm currently learning android using the book from Big Nerd Ranch. Right now I'm creating an app where I recently changed the startup activity. Now the problem is, that whenever I run the application from my IDE (IntelliJ) either on my phone or my AVD, it starts the wrong activity (The one it used to start on before i changed it). However, if i open the app by clicking on the icon on the phone, it starts the right activity.
I want it to start using the activity "CrimeListActivity". Here is my manifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bignerdranch.android.criminalintent"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8"/>
<application android:label="#string/app_name">
<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"
android:label="#string/app_name">
</activity>
</application>
Maybe check the default Activity inside Android Studio
take a look

HOME activity will not show up or act as home activity

This is my first time asking a question on on here, but I have found the answer to innumerable questions I've had before on here. However, I just can't make this one work. I'm simply trying to write an app to replace the homescreen. Here is what I am trying, and I can't see what I'm missing.
To keep it as simple as possible, I reduced it to just this testing application. The only thing I changed after starting a new project was the manifest.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hometesting"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<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=".HomeActivity"
android:theme="#style/AppTheme"
android:launchMode="singleTop"
android:stateNotNeeded="true" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME"/>
<category android:name="android.intent.categoty.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
I have tried it both in the emulator and my own phone, in the latter, it doesn't show up in the chooser. I can select it as the default home application in the user settings, but when i hit the home button, it just brings up the chooser without my app as an option. The pre-installed home screens and one other app that I downloaded show up as options, but my app doesn't. In the emulator, a click on the home button just brings up the default homescreen.
I have tried it with and without the separate launcher activity, and with and without the LAUNCHER intent. I have tried installing, uninstalling, restarting, and every permutation thereof.
All I want is for the home button to lead back to an activity that I wrote. Any help would be greatly appreciated.
Update: I also tried it on a generic cheap Chinese device, and still nothing.

Android Lollipop calls onCreate after finish()

This is a strange behavior of Android Lollipop 5.0.
I have two activities, A and B.
A starts the activity B. When I click on the back button, in activity B, Android calls onCreate method on A.
This behavior is observable only in Lollipop 5.0.
In the other versions, onCreate is never called after finishing another activity.
What is the problem?
This is my Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.example"
android:versionCode="1"
android:versionName="1" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="21" />
<application
android:name=".Application"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppThemeMaterial" >
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name=".activities.ActivityA"
android:configChanges="orientation|keyboardHidden|screenSize"
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=".activities.ActivityB"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/activityB" >
</activity>
</application>
</manifest>
please make sure that option not selected
Developer Options -> Don't keep activities
What I think is happening is that when you leave the Activity A, onStop() is being called on activity A since its completely hidden and B is on top of it.
Usually now when you resume activity A after pressing back onStart() is called and then onResume().
But, if you see the Activity LifeCycle, it is technically possible for onCreate() to be called as well, in the case where your app's process is killed by the system if other apps with higher priority need more memory.

Android app always opens the first activity on resuming

I'm working on an application that currently has two activites, a log in activity and a "frontpage" activity after that.
Whenever I switch away from the application and resume it either by relaunching it or using the application switcher, it will always re-open the log in activity. Even if I switch to my app from within the frontpage activity, it opens the log in activity.
None of my other apps have ever done this, even though they obviously all have a filter for the launcher in AndroidManifest.xml. I am aware that it is supposed to do this when the activity is killed, but I cannot comprehend why it would do that.
This is my AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="nl.vertinode.facepunch"
android:versionCode="1"
android:versionName="1.0">
<!-- Android 2.2 -->
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="8" />
<!-- Internet access -->
<uses-permission android:name="android.permission.INTERNET" />
<application android:icon="#drawable/icon" android:label="#string/app_name" android:name=".FPApp">
<!-- Login form -->
<activity android:name="nl.vertinode.facepunch.LoginActivity" android:launchMode="singleTask" android:theme="#android:style/Theme.Light.NoTitleBar" android:windowSoftInputMode="stateHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Frontpage view -->
<activity android:name="nl.vertinode.facepunch.FrontpageActivity" android:theme="#android:style/Theme.Light.NoTitleBar" android:windowSoftInputMode="stateHidden">
</activity>
</application>
</manifest>
What could I be doing wrong?
I'm going to guess this has to do with your android:launchMode being singleTask.
Try singleTop instead and see if you have the same problem. Also it could have to do with some code you have in your onPause for the other activities. Does it go back to your Login activity after going to sleep/waking back up as well?

androidManifest and intent-filter to order activity

I have 3 Activity in my androidManifest,
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="zepod.whatelsecomics" 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=".Activity1"
android:label="#string/list1">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Activity2"
android:label="#string/list2">
</activity>
<activity android:name=".Activity3"
android:label="#string/addItemToList2">
</activity>
</application>
The first one call the second one
The second one call the third one
The first one activity is the main activity.
The result of the third one activity is an updated list in the second one (just a form).
But now, if i clik the back button i came back at the third one
How can i force the app to came back at the first activity?
I suppose this depend by androidManifest but i don't understand the intent-filters order
Can someone help me?
When starting to the third activity, call finish() to remove the second activity from the stack. That's the easiest way.
There are other ways. This question has been asked a million times on SO, search for it and you'll find alternatives.

Categories

Resources