android-service

Android: How can i show a toast from a thread running in a remote service?

断了今生、忘了曾经 提交于 2019-11-26 16:28:01
问题 Android: How can i show a toast from a thread running in a remote service? Whenever i run from a different thread in a service, the app crashes... public class BroadcastService extends Service { private static final String TAG = BroadcastService.class.getSimpleName(); private MessageFormatter mFormatter = new MessageFormatter(); private BroadcastComm broadCastComm = new BroadcastComm(); private Task commTask = new Task(); private volatile static boolean stopBroadcastRequested = false; private

Check if Activity is running from Service

泄露秘密 提交于 2019-11-26 16:04:33
问题 How can a Service check if one of it's application's Activity is running in foreground? 回答1: 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

Get Context in a Service

怎甘沉沦 提交于 2019-11-26 16:04:20
Is there any reliable way to get a Context from a Service ? I want to register a broadcast receiver for ACTION_PHONE_STATE_CHANGED but I don't need my app to always get this information, so I don't put it in the Manifest . However, I can't have the broadcast receiver be killed by the GC when I need this information so I'm registering the broadcast receiver in a Service . Hence, I need a Context to to call registerReceiver() . When I no longer need the ACTION_PHONE_STATE_CHANGED I unregister it. Any tips? Service is a Context user2138983 Service extends ContextWrapper which extends Context .

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

和自甴很熟 提交于 2019-11-26 15:52:30
问题 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

How to always run a service in the background?

我的未来我决定 提交于 2019-11-26 15:41:32
I am in the process of creating an app that is similar to the built-in SMS app. What I need: a service that is always running in the background every 5 min. the service checks the current location of the device and calls a web service if certain criteria are met, the service should generate a notification (just like the SMS app) when the notification is clicked, the user is taken to the app (just like the SMS app) when the app is installed the service should be started when the device is rebooted, the service should be started What I have tried: - running a regular service which worked just

Android. Is WorkManager running when app is closed?

早过忘川 提交于 2019-11-26 15:38:30
问题 I want to schedule nightly database updates. So I use new Android WorkManager. My understanding is that once scheduled it will always run in the background independently from the app's lifecycle. Is that right? My first tests show that Work is only being performed when the app is running. val locationWork = PeriodicWorkRequest.Builder(UpdateDatabaseWorker::class.java, 24, TimeUnit.HOURS) .addTag("DATABASE_UPDATE_SERVICE") .build() WorkManager.getInstance().enqueue(locationWork) 回答1: Based on

Using a listener after an android application is closed

爷,独闯天下 提交于 2019-11-26 14:48:13
问题 I've just been reading about adding a service to my application, and since 7/8 there are now service restrictions to improve phone performance. I've seen that the recommended approach is to use a job scheduler, but will that not just periodically start a new listener if I did that? Basically I update my database, and using a snapshot listener I want to update my user in real time. When the app is closed, I'd like to send a notification. My issues (if I'm correct) are that constantly making a

Samsung “App optimisation” feature kills background applications after 3 days

假装没事ソ 提交于 2019-11-26 14:19:08
问题 We are currently developing an Android app that is a fitness-tracker application. It runs constantly in the background, and it works fine on most devices, but we've been having issues with the application dying completely on some Samsung devices. After some investigation, it seems like some Samsung devices has a completely custom "App Optimisation" feature (http://forums.androidcentral.com/samsung-galaxy-s6/599408-app-optimisation-after-updating.html), which is basically a (very) primitive

Create only one instance of Service (Android)

徘徊边缘 提交于 2019-11-26 14:14:44
问题 How can I make sure that only one instance of Service is created? I have checked some functions with logging (WeatherService is the class who extends Service): Log.i(TAG, "Start Id:" + WeatherService.this.hashCode()); Log.i(TAG, "End Id:" + WeatherService.this.hashCode()); It gives different hash codes even when I am sure that the same function is running twice (downloading): 09-12 01:00:55.195: INFO/WeatherService(7222): Start Id:1137653208 09-12 01:00:57.235: INFO/WeatherService(7222):

Permission Denial: startForeground requires android.permission.FOREGROUND_SERVICE

て烟熏妆下的殇ゞ 提交于 2019-11-26 12:52:58
问题 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