Android app always opens the first activity on resuming - android

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?

Related

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 manifest for USBAccesory

I am making an app that communicates with a piece of usb hardware made by my company (this is the only app allowed to talk to the usb accessory, it's not a public api). I am having difficulties setting up the proper launch modes in the manifest.
There are three components to the app: the main activity, a login activity, and the USBService.
I'm assuming the intent for the main goes to the login activity, and the intent for the usb goes to the USBService, but I am not sure if I do this, will this start the service if the app is not running? More over, if it does, how do I fetch an already existing service?
What type of structure should I be looking at for the manifest file? (specifically, intent-filters, and appropriate launch modes... I've read a few documents about the launch modes but I am still not sure I quite understand... There should only ever be at most one instance of each activity/service, and they need to communicate together.
edit: it is not necessary for communications to start before the app is open, nor is it necessary to launch the app automatically when the usb is connected.
edit: my manifest as it stands, looks like:
<uses-feature android:name="android.hardware.usb.accessory" />
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name="mainpackage.MainActivity"
android:label="#string/app_name"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED" />
</intent-filter>
<meta-data
android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED"
android:resource="#xml/accessory_filter" />
</activity>
<activity
android:name="mainpackage.LoginActivity"
android:label="#string/title_activity_login"
android:windowSoftInputMode="adjustResize|stateVisible" >
</activity>
<service android:name="updater.USBService"
android:exported="false" >
<!--
-->
</service>
</application>
in your manifest add
<manifest ...>
<uses-feature android:name="android.hardware.usb.host" />
<uses-sdk android:minSdkVersion="12" />
In this case, the following resource file should be saved in res/xml/device_filter.xml and specifies that any USB device with the specified attributes should be filtered:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<usb-device vendor-id="1234" product-id="5678" class="255" subclass="66" protocol="1" />
</resources>
Hope this help.
Your manifest looks good,
I think you make a good choice for putting the intent-filter "android.hardware.usb.action.USB_ACCESSORY_ATTACHED" in the mainActivity and start the application in this activity,
and again I think it's a good choice to start your mainActivity in SingleTop launch mode,
because if an instance of the mainActivity already exists at the top of the current task, the system going to launch this activity, no new instance of this activity will be created.
For a best understanding of the different launch mode available in android,
I think this link may help you :
http://www.intridea.com/blog/2011/6/16/android-understanding-activity-launchmode
To make a long story short I think you'll be all set with this manifest as is.
To Use Android Devices min SDK version should be set to 12 and need to declare following line in AndroidManifest.xml file
<>
<uses-sdk android:minSdkVersion="<version>" />
...
<application>
<uses-library android:name="com.android.future.usb.accessory" />
<activity ...>
...
<intent-filter>
<action android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED" />
</intent-filter>
<meta-data android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED"
android:resource="#xml/accessory_filter" />
</activity>
</application>

Starting an Activity First in 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.

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