App is not maintaining the state after installation - Xamarin android - android

Recently I noticed one thing in my app.
I created apk for my app say ABC.apk and copied to my device and installed it by clicking on it. After the installation got successfully completed, I got 2 options 'Done' and 'Open', the usual options we get after installation.
I clicked on 'Open' and run the app. I moved to some screen and I minimized the app and moved to someother app, when I click my ABC, it started from my first screen.
It was just fraction of seconds I moved back to it, hence it should not be killed though launched it like it is first time.
Few things I noticed I if I explicitly killed this first instance from background running apps and start the app again it is not giving me this problem, same if I click 'Done' instead of 'Open' it works fine.
Is there anyone who are facing same issue, or have some solution for it?
Thanks in advance.
Prajakta

The problem is the way that the app gets launched from the installer doesn't exactly match the way Android launches apps from the HOME screen. Because this, if you initially launch your app from the installer, when you then later launch the app again from the HOME screen, Android doesn't recognize that the app is already running and just creates a new instance of the root Activity and adds it to the existing task on top of whatever activities are already there.
This is why, if you kill the app and start it again from the HOME screen, you won't ever see this strange behaviour.
This is a nasty Android bug which has been around since the dawn of time and is still broken, even though countless issues have been opened about it and the behaviour is reproducible and well-documented.
See the following issues and questions:
https://issuetracker.google.com/issues/36941942
https://issuetracker.google.com/issues/36907463
https://issuetracker.google.com/issues/64108432
App restarts rather than resumes
Re-launch of Activity on Home button, but...only the first time
There is a workaround documented in my answer to
Re-launch of Activity on Home button, but...only the first time

Just some general comments that come to mind that you must consider that can cause problems.
If you are trying to deploy an apk, did you switch from debug to release before building it? Make sure you are doing a full release. Do a clean and rebuild while in release mode as well.
Did you sign the apk?
Make sure all the necessary (if any) permissions are set in the manifest that will be needed by your app, on the device.
Hope these help point you in a direction.
Mike

Related

Main Activity Relaunched on App Close

I am making an android app on API 15 for a mobile computer application.
In this app I have a background service, a lot of classes inheriting from AsyncTask, and some sql updates and broadcasting to the service on the app pausing.
I have recently discovered an issue where going to a specific screen in my app, hitting the home button, bringing up my app list, and swiping away my app to kill it results in the app closing and then soon restarting itself at the main activity. It should just close normally.
I have tried placing breakpoints everywhere, and even disabling the background service, but i cannot seem to find any indication of what is restarting the app when it is closed.
I just tried getReferrer inside a try catch and my app says it isnt responding and shuts down even though its in a try catch block.
Both problem seem odd to me.
If it means anything, Android studio will still be debugging the app once it has opened again after i close it.
If anyone could shed some light on what could be restarting my app after i close it, it would be very helpful.
EDIT:
I am using Start_Not_Sticky. this and Start_Redeliver_Intent are ideal option from what i have read.
Thank you to Kevin Krumwiede for suggesting grepping all my code for the main activity's name. I had no idea I could go through all of the code in my project within the IDE instead of going one file at a time.
I had previously tried going through all my classes and searching each individually for reference to it with ctrl+f but i never considered looking in one of my activities that i hadn't modified in months for the new issue.
when I used ctrl+shift+f it all came together as i saw the startActivity function inside of OnDestroy(), not sure how i never noticed this issue before.

How come if you click an ad in my game it causes the game to restart?

I just started to experiment with ads for the first time so I am a complete beginner at this stuff. I have the ads running at the right screens which is good but if you click an ad and it takes you out of the game it causes the game to restart. I made my game in libgdx and I use the pause function and what not but it obviously doesn't call that and in fact just causes a full restart which would make a lot of users angry. Anyone else having this issue or I am doing something wrong?
I am using admob by the way.
EDIT
I also just realized that it happens on my nexus 5 and not my nexus 7.
I think it happened to me some while ago with a game that tried to implement fb sign in functionality. The second it got back from the sign it, it restarted.
What might be happening in your case is that when you click on the add, android switches from your LibGDX activity to the admob activity. Once you come back, the onCreate method gets called again, therefore restarting your app from scratch. (A simple way to verify this is just to add a Log call everytime the app on create method is entered, and check the behaviour of your app)
If that is the case, a possible workaround for it is checking that if your game has been already initialized it should not instantiate it again.
The restart means that your app has crashed. That's standard Android behaviour.
I suspect you have wired something up incorrectly. Look at you log. There's a good chance something hasn't been initialised that should have.

Handling app suspend/resume on Android in Kivy

I started developing an app with Kivy for Android and managed to build and run an APK today.
Couldn't find a straight answer on how to handle my app being suspended and resumed by a user without going through the initialization/loading screen? Is there a special mechanism that will handle this?
It is rather annoying that every time I send the app to the background and bring focus back to it there is that loading screen popping up.
I have never used Kivy or developed for android, but I was able to find:
This
From the link:
If you just want your app to not be closed completely (so that it doesn't restart entirely with the splash screen etc. every time), you just have to add an on_pause method to your App class, and it should return True. You can also do any pre-pause stuff in this method. However, the app doesn't really keep running, it just keeps memory state.
If you want it to do computations in the background you can use Python-for-android.
Kivy has an on_pause and on_resume methods that you can use to handle these events. These are methods of the main App class that are called automatically for you.

Application does not start?

This is a weird bug I have come across where my activity or say application does not start. As soon as I touch icon of my app and I press lock button , then when i unlocked it I can not see my application opened and moreover it is not in the active application status also. As per the flow of application runs it should get opened behind or atleast can be seen in Active Application status?
Is there any way to resolve it.
Maybe you can trace your code from adb or find tools in android sdk tools folder finder the tool to get the logs

mGWT State management

During testing of mgwt application in emulator, if we suddenly stop and go to home page in emulator and start the application again, it will directly load the last page where we were wokring. Why it is not resetting it to the first page?
In GWT on module function, I am always loading the default place. I need to explicitly go and remove data and then start application to proceed.
How to overcome this problem programatically? Do we have any reference for it? I have not used gwt-phonegap, it is just mgwt with GWTp framework application.
I think your application isn't stopped. I think it is running in background. If you bring it back to front, it shows the same screen again.

Categories

Resources