android-service

Android O Replacement for getRunningServices

风格不统一 提交于 2019-11-30 04:43:28
In previous versions of Android, I used this method to find if a service from another app was up and running. It worked reliably for me: ActivityManager manager = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE); List<RunningServiceInfo> services = manager.getRunningServices(Integer.MAX_VALUE); However, with Android O this is now deprecated and will only return information about the calling apps services. I've looked into other solutions, but I don't want to ask the user for more permissions, (UsageStatsManager, NotificationManager, etc). Is there an alternate solution for obtaining

If android restarts a Service is onCreate called again?

给你一囗甜甜゛ 提交于 2019-11-30 03:59:26
From my little android knowledge I understand that android OS can kill my service under extreme memory conditions. I have created a service that returns START_STICKY . The service is meant to run in background. If android is about to kill my service, will it call onDestroy ? And when it restarts it would it call onCreate ? See here, the dev guide. http://developer.android.com/reference/android/app/Service.html#ProcessLifecycle onCreate() is only called when the process starts, which can either be the first time the service is running, or if it was killed on restarted, essentially this is

How to simulate a service killed by the Android system

我只是一个虾纸丫 提交于 2019-11-30 03:43:55
问题 While developing I wanted to test the situation where the system kills a service. This is because I'm loosing connection when communicating between the Android Wear and the handheld. And I think that it is related with the system killing some services. Does anyone have a suggestion on how to approach this? 回答1: if you're developing in Android Studio while you are running your application in android wear side try to hit the kill button displayed in the console. When you hit this button all the

How to address android lint complaint about exported Firebase Messaging service implementations?

左心房为你撑大大i 提交于 2019-11-30 02:42:50
Following the Google developer instructions on implementing Firebase in my app , I notice that android lint complains. The idea is that we have to implement two services which inherit from Firebase services: public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService { ... } public class MyFirebaseMessagingService extends FirebaseMessagingService { ... } and then register those services in the manifest. But, it's not quite perfect. In particular, these two recommended AndroidManifest.xml service entries do not contain any special permissions: <service android:name="

Android java.lang.IllegalArgumentException: Service not registered

自古美人都是妖i 提交于 2019-11-30 01:19:39
I have a setup that looks something like this: class MyFragment implements SomeEventListener { Application mAppContext; boolean mBound; boolean mDidCallUnbind; MyIBinder mBinder; ServiceConnection mConnection = new ServiceConnection() { @Override public void onServiceConnected(ComponentName name, IBinder service) { mBound = true; mBinder = (MyIBinder) service; mBinder.getThings();... } @Override public void onServiceDisconnected(ComponentName name) { mDidCallUnbind = false; mBound = false; mBinder = null; } }; ... @Override public void onSomeEvent() { mAppContext.bindService(...); } void

Using Dagger 2 to inject into service

北慕城南 提交于 2019-11-30 00:43:50
I have an app which is basically a service that runs all the time and alarms the user when something happens. When the service creates the alarm, it needs to give it his context so that the alarm can do callbacks to the service when something happens. For example: public MyService extends Service{ private SomeAlarm alarm; @Override public void onCreate() { super.onCreate(); alarm = new SomeAlarm(MyService.this); } } How can I inject the SomeAlarm class into the service, and give the SomeAlarm the service context as a variable? I wrote the code from the top of my head, so there could be a typo

java start one background thread after another complete

北战南征 提交于 2019-11-29 23:49:06
问题 I saw this question: how to run one thread after complete another thread , but the answer to it is not appropriate for me. I have such kind of java code for Android: public void startTask(Runnable r) { running = true; Log.i(tag, "-----------start.Runnable-----------"); Thread first = new Thread(r); first.start(); Thread second = new Thread(new Runnable() { @Override public void run() { // TODO Auto-generated method stub running = false; } }); } first Thread takes as param Runnable object with

Service gets paused while app is in background && screen is locked

淺唱寂寞╮ 提交于 2019-11-29 23:29:47
问题 Inside a Foreground Service I encode media with FFMPEG. By logging the encode progress I noticed the process gets paused(in some devices) while device connected to adb over wifi(NOT USB) && screen is locked . I tried : try { final PowerManager mgr = (PowerManager) getSystemService(Context.POWER_SERVICE); if (mgr != null) { wakeLock = mgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "TAG:WakeLock"); if (!wakeLock.isHeld()) { wakeLock.acquire(); Log.i("AppController","Engaging WakeLock"); }else{

How to Create a android native service and use binder to communicate with it?

心已入冬 提交于 2019-11-29 23:19:05
My basic task is to create a native service in android and then write a simple native program to test it. lets say i want to write a simple service which return me sum of 2 integers. I have to use binders to talk to it from the program, I have tried to google around but i cant find a precise example. I need to know how to create a native service and find it in the program and if needed in Java also. If you're creating a normal Android application using the NDK, you can't use Binder because it's not part of the NDK APIs. Look in the NDK docs/STABLE-APIS.html for the full list of stable APIs,

Using Job Scheduler in Android API <21

你说的曾经没有我的故事 提交于 2019-11-29 22:52:48
I was looking at a scheduling tutorial by Vogella . It mentions the Job Scheduler API that was introduced in API 21 of Android. My question is can it be implemented in APIs lower than 21 (Lollipop) but not less than Android version 3 (Honeycomb)? from now on (after I/O 2015), you can also use new GcmNetworkManager. How to use it and how it works is described here - https://developers.google.com/cloud-messaging/network-manager It does a lot cool stuff like it persists your tasks trough reboots. On Lolipop it uses JobScheduler, on pre-Lolipop it uses it's own implementation. EDIT: An example