android-service

Shared preferences between two processes of the same application

北城余情 提交于 2019-11-27 12:44:48
I'm writing an Android app that contains both UI and separate processes running. I want to share simple information between the main process and a service defined in my application that is executed in a different process. I find to messy to use AIDL for inter-process communication for this purpose. The question is: Is it safe to use Shared Preferences of the application for communicating between this two processes? This is: both read and write the same shared preferences. I'm wondering if it actually works. In android developers reference about shared preferences (http://developer.android.com

Check if Activity is running from Service

邮差的信 提交于 2019-11-27 12:35:19
How can a Service check if one of it's application's Activity is running in foreground? Rasel Use the below method with your package name. It will return true if any of your activities is in foreground. public boolean isForeground(String myPackage) { ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE); List<ActivityManager.RunningTaskInfo> runningTaskInfo = manager.getRunningTasks(1); ComponentName componentInfo = runningTaskInfo.get(0).topActivity; return componentInfo.getPackageName().equals(myPackage); } Update: Add Permission: <uses-permission android:name=

Keep location service alive when the app is closed

与世无争的帅哥 提交于 2019-11-27 12:33:27
问题 I have a service which sends a notification when the user changes his/her location. This service is working fine, but the problem arises when the user closes the app as the service closes too. How I can make the service still alive even though the application was closed? My Service is: public class LocationService extends Service implements LocationListener { public final static int MINUTE = 1000 * 60; boolean isGPSEnabled = false; boolean isNetworkEnabled = false; boolean canGetLocation =

Getting java.lang.ClassCastException: android.os.BinderProxy every time i declare and run two services

痞子三分冷 提交于 2019-11-27 12:29:54
问题 I am encountering following binder.proxy exception every time i declare and run two services. One service runs in different Process(Private to app) and another service runs in same process as My Application is running in(Default App Process) with a Binder Implementation. AndroidManifest.xml: <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.service.check" android:versionCode="1" android:versionName="1.0" > <uses-sdk

How to restart service after the app is killed from recent tasks

给你一囗甜甜゛ 提交于 2019-11-27 12:13:31
I have created a service to fetch current location of the device in periodic intervals. I want the service to run in the background even if the app is cleared from recently opened apps. Currently the service runs in background only until app is present in the recently opened apps but stop immediately when app is swiped off (or killed in some other way). I have tried all sort of help available in stack overflow yet I am unable to solve this. Please help. Here is my code for the service. package com.packr.services; import android.app.AlarmManager; import android.app.PendingIntent; import android

Android service crashes after app is swiped out of the recent apps list

馋奶兔 提交于 2019-11-27 12:07:38
I have a service that gets started (not bound) by an activity. If the activity gets destroyed (e.g. by pressing the back button), the service continues to run, this is of course intended. However, if I swipe the activity out of the 'recent apps' list, the service gets restarted immediately. This is reproducible, every time the activity/app is swiped out of the list, there is a new call to the service's onCreate-method. No call to onDestroy in between! First I thought the service gets killed by android, even though I saw no reason for the kill (neither the activity nor the service do resource

How it is possible Service run indefinitely and also allow binding in android?

岁酱吖の 提交于 2019-11-27 12:02:44
I want a service which can run in the background until I stop, even if the component that started it is destroyed and also allows binding to the activities. How it is possible ? As per android bound services document - there are three ways of creating bound service Extending Binder class. Using Messenger. Using AIDL. I have created a bound service using messenger (2nd method). Activity is bind to service in its onStart() method and unbind in its onStop() method. Two way messaging (between activity and service) works properly. But problem is that when activity unbinds service, service is

java.lang.RuntimeException: WakeLock under-locked C2DM_LIB

我怕爱的太早我们不能终老 提交于 2019-11-27 11:04:58
问题 I have uploaded my application on google play but users have reported the following exception java.lang.RuntimeException: WakeLock under-locked C2DM_LIB . This exception occurs when I try to release the WakeLock . Can anyone tell what could be the problem. 回答1: I have traced same exception in new GCM Library too. Actually old C2DM Android library have same error, same crash, and Google hasn't fixed it yet. As I can see by our statistics, about 0.1% of users experiencing this crash. My

Set “allow” permission by default in “Asus auto start manager” from code

你离开我真会死。 提交于 2019-11-27 10:52:23
问题 I have an application which needs to run in the background, so I'm using a WakeFullService for that. But in Asus Zenfone it's not working because Auto start manager does not allow the app to run. My expectation is: To set "allow permission" in auto start manager during our app install or at the time of app opening. Is there any API available from ASUS Auto Start Manager which can help me check the permission status of my app so that I can notify the user via normal text alert to turn on the

Permission Denial: startForeground requires android.permission.FOREGROUND_SERVICE

て烟熏妆下的殇ゞ 提交于 2019-11-27 10:49:27
Lately we have suddenly been seeing a few of the following stack traces. Why could that be? This is from when the app tries to move an audio commentary service into the foreground with a media notification and everything. java.lang.SecurityException: Permission Denial: startForeground from pid=1824, uid=10479 requires android.permission.FOREGROUND_SERVICE at android.os.Parcel.createException(Parcel.java:1942) at android.os.Parcel.readException(Parcel.java:1910) at android.os.Parcel.readException(Parcel.java:1860) at android.app.IActivityManager$Stub$Proxy.setServiceForeground(IActivityManager