Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I want to perform some activities like clearing cache, singletons clearing etc. I will write all this code in Service which will be background but I need this service to be triggered only when application is closed or exited.
I cant put my code to statrt service in onDestroy of activity as whenever i will move between my activities it will call onDestroy of previous activity.
How to know if application is exited.
Example will really help.
Thanks.
The ActivityManager should be what you are looking for.
For example see here
in your main activity, capture the "back" key and check for Activity.isTaskRoot() whether it is the last one. If yes, your app is going to "exit", then do some communication with your service.
please note pressing the Home key doesn't mean to "exit" your app
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I am getting installed widgets but I need to find out only running widgets of home screen. Is there any possible solution.
Thanks in advance.
Write your own home screen implementation, where you allow the user to add app widgets to that home screen. Then, you will know what the "running" app widgets are.
Other home screen implementations do not have to publish this information to third parties, and hopefully they do not, for privacy and security reasons.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I want a set of statements to be executed just before bluetooth turns off manually or before a connection is closed when user goes out of range.
Which functions to use / how to do it?
You implement a BroadcastReceiver which listens for ACTION_STATE_CHANGED. In the onReceive method of your BroadcastReceiver, you put the set of statements you want to execute. See this.
There is no "Just Before" a Bluetooth connection drops or the state is change. Android will tell you when it drops, becomes inactive or is turned off.
Have a look at this page, because you can listen to ACL_BLUETOOTH_DISCONNECTED - similar to ACTION_STATE_CHANGED, but be aware of the functionality it contains as it is not quite what I expected.
What triggers the BluetoothDevice.ACTION_ACL broadcasts?
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have specifications from my employer. He wants me to track the use of 3rd party apps from inside of our application. Our application is suppose to act as an operating system. We launch 3rd party apps from our application. Is there any way to track how long a user is using these apps?
The only thing I could think of is starting the timer when I start the intent to launch the app, and upon return to our application stopping the timer. Any ideas on a more concrete idea? Thank you in advance.
Have you looked into Interacting with Other Applications does any of that apply? Your method does seem like the only possible way but I would do it by checking the system time in the onPause and onResume J.I.C your stops whilst being on the other app :) Hope I helped!
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I got a problem with my app when the screen turns off (because of system screen timeout) my application finishes.
I search but didn't find something helpful.
Is it a common problem or does it have a fix?
you shud not call finish() in onPause. it could be called for variety of reasons(check doc.). why you want to kill your activity when user switches app? its not recommended.
here are some posts, but there is no api available to detect app going in background.
How to detect when an Android app goes to the background and come back to the foreground
http://nathanael.hevenet.com/android-dev-detecting-when-your-app-is-in-the-background-across-activities/
I want when the user leaves this activity to finish but not the screen thnx
Take finish() out of onPause(). Put it wherever the user leaves the Activity. So, assuming you have code that starts a new Activity, put finish() after startActivity().
You also could use the flag android:noHistory in your <activity> tag of your maifest.xml so that the Activity is removed from the stack whenever it starts a new Activity. Both of these methods do the same job it just depends on how you want/need to implement it.
The reason it closes when the screen turns off is because your app calls onPause() at that time so removing the call from that method would keep it from closing when the screen turns off.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
When my app starts, the launcher activity's onCreate() method gets called normally only once. But that is immediately followed by two calls to onResume(). When I inspect the code, both instances are of the same class but only one has instanced members from the onCreate(), obviously.
Everything is working fine, though. I am just curious trying to understand why this is happening. Does anybody have any ideas? I'm using SherlockFragmentActivity, does that have anything to do with it? I'm happy to provide more information as needed. I just don't know now what else is relevant.
Thanks!