android:how to check if application is running in background
-
I am newbie to android. I have client server based application. Server keeps on sending the update notifications to client after every single minute and at client side my app receive those updates and display it using Toast. But now my problem is whenever my client app goes into the background server keeps on sending the update notifications and my client display it as if the application is in foreground. I am not getting how to check that application is running in background.
-
Answer:
http://developer.android.com/guide/topics/fundamentals.html#lcycles is a description of the Life Cycle of an android application. The method onPause() gets called when the activity goes into the background. So you can deactivate the update notifications in this method.
Rupesh at Stack Overflow Visit the source
Other answers
To check if your application is sent to background, you can call this code on onPause() on every activity in your application: /** * Checks if the application is being sent in the background (i.e behind * another application's Activity). * * @param context the context * @return <code>true</code> if another application will be above this one. */ public static boolean isApplicationSentToBackground(final Context context) { ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> tasks = am.getRunningTasks(1); if (!tasks.isEmpty()) { ComponentName topActivity = tasks.get(0).topActivity; if (!topActivity.getPackageName().equals(context.getPackageName())) { return true; } } return false; } For this to work you should include this in your AndroidManifest.xml <uses-permission android:name="android.permission.GET_TASKS" />
peceps
You can use http://developer.android.com/reference/android/app/ActivityManager.html#getRunningAppProcesses%28%29 in ActivityManager .
metdos
Related Q & A:
- How can fix Internet Explorer currently running with Add-on disabled? Anybody that can help me?Best solution by Yahoo! Answers
- How do I connect a laptop running XP to a wireless HP printer?Best solution by Yahoo! Answers
- How to do flips in Free running?Best solution by youtube.com
- How to sing really fast without running out of breath?Best solution by wiki.answers.com
- How will check my uk visa application status?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.