Android application doesn't close - android

I've written an application for Android, but it doesn't close and it also starts automatically with the system. I don't know why, but it can't be closed, even through the Task Manager. So I would like to know why it doesn't close.

I'm sure you have read how Android apps aren't really supposed to close. That aside, I also needed my app to terminate when no longer visible. First I tried
System.exit();
That worked just fine but it isn't the proper way to do it, the best way is to call
finish();
I'm sorry if you had already tried/were aware of those solutions; it wasn't clear from your question.

Related

Starting a function in the onCreate (without a button click)?

I know this might be a basic question, but I am a beginner and I haven't been able to find an answer.
I would like to know, if it is possible to trigger some function/action while creating an activity. eg. trigger a void without user intervention, start an animation automatically after an Activity is created etc.(at the moment I am trying to trigger an animation without a button click, but this question is general and not specific code related).
I know how to bind an action to a button click and every resource I have found is doing that, I haven't, however, been able to start an animation or a void without it and I am not sure if it is possible. (I have tried using Handler, it worked but prevented the rest of the code being executed - I might have done it wrong, though as I really am a beginner)
so my question(s): Is it possible to trigger a function/animation without user intervention(click)?
If so, where can I find some resources to read about it? (I tried reading Android documentation already)
Thank you very much and I apologize if the question is too simple, I know it might be.
Please have a look at this photo.
It clearly explains the lifecycle of Android activity.
To answer your question, yes, it is possible to trigger a function/animation without user intervention(click). You have to call the function from onStart() activity.

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.

ask for confirmation before closing emulator in android

Is there a way I can disable close button of the android emulator or get a confirmation before closing.
After several runs I accidently closed the emulator.
Also it takes a lot of time to load the emulator again.
There is no built-in support anywhere for this. You have to search for 3rd-party solutions.
Here is one I found quickly.. http://lifehacker.com/5183947/noclose-disables-windows-close-button.
Go to the website, let it load, and then you have to search for NoClose. It is there, but it does not scroll automatically to the app to download.
You can also try to search for another similar solution.

Unfortunately app has stopped measures

This might be a weird question to ask.
But i want to make my application better.
I think i can find a solution here.
I am developing android apps..
It almost complete. What i am trying to figure it out is, how android error works.
I mean, i make an error so i will know when my apps crash, it will direct to some activity.
Like i delete an imagebutton in xml so my app will crash and unfortunately app has stopped will show up.
How do i direct to an activity after i click ok on that dialog ?
Is it possible to achieve something like that ?
Instead of crashing it would be better to implement try and catch where needed.
http://docs.oracle.com/javase/tutorial/essential/exceptions/try.html
This allows the app to softly deal with an error and continue. You could then redirect, but it would be better to just let it continue so the user wouldn't have to be interrupted.

Pause an Android App with Phonegap

Is there any way to programmatically pause an Android app in Phonegap? I would like to mimic the behavior that occurs when you hit the HOME button. I've already had to overwrite the back button handler using this, and while in most cases I want it to do my action, when in a particular state the user would expect the app to minimize, and I want to replicate this behavior.
Keep in mind, on Android this is not the same as closing the app. That is quite easy to do with device.exitApp(); but I would like it to remember its state and keep running in the background. Especially if there's still an asynchronous job being done in the background.
Is there a feature in Phonegap to achieve this?
Possible duplicate of Manually pause an application in Android Phonegap, but I couldn't find some of the tools the OP mentioned there such as navigator, so I was nervious to totally edit and rewrite their post
The simple answer appears to be: no.
However, for anyone else that comes down this path, its not impossible. It's just that there isn't a feature of Phonegap to do it for you.
The Android equivalent of "sleeping an app" is actually just opening another intent. Specifically, opening the "Home" intent would sleep the running app and bring you back to the home screen. But as far as I can tell from asking around and scoping the docs, Phonegap doesn't have a direct way of opening intents.
What you (supposedly) can do is one of two things:
This plugin is supposed to be promising
Call the Java code that does it yourself using the means described here
Mind you, as of right now I've decided to not go any further with this, so I make no promises about either of those means, having not attempted them myself.
I invite anyone else who decides to pursue this further to update their experience here.

Categories

Resources