android-service

BroadcastReceiver within a Service not receiving broadcasts Android

雨燕双飞 提交于 2019-11-29 14:41:28
I've got this app, in which users update certain variables in an Activity, and this Activity passes the new variables to a IntentService using a BroadcastReceiver. However, the BroadcastReceiver in the IntentService doesn't seem to be receiving the broadcasts. This is the code within the service to create the broadcast receiver protected class UpdateReceiver extends BroadcastReceiver{ @Override public void onReceive(Context context, Intent intent){ Log.d("receiver", "Got message: "); //state=3; //Toast.makeText(context, "got it", Toast.LENGTH_SHORT).show(); } }; And here's the code to register

how to check the top activity from android app in background service

笑着哭i 提交于 2019-11-29 12:57:51
In my app i want to check whethere any other app launches or not from my app.So i am currently usimg Activitymanager to find the top activity like this ActivityManager am = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE); List< ActivityManager.RunningTaskInfo > taskInfo = am.getRunningTasks(1); Log.d("topActivity", "CURRENT Activity ::" + taskInfo.get(0).topActivity.getClassName()); ComponentName componentInfo = taskInfo.get(0).topActivity; componentInfo.getPackageName(); But i want to run this code in background service.So that i can detect When other app launches through this.So is

Getting a Handler from a Thread from Service to Activity

前提是你 提交于 2019-11-29 12:56:11
Situation: activity binds to started foreground service. service hands out local binder to activity. activity gets reference to service through a getService() call. activity wants to communicate directly with a thread running in the service using messages. It calls the mService.getThreadHandler() method from the activity. Problem: how do I get a Handler from the current running thread into the active activity, so that I can post messages directly to the threads messagequeue? I don't what to use a messenger within the service, I want to directly communicate with the thread in the service from

How to auto restart a service when killed?

末鹿安然 提交于 2019-11-29 12:49:47
I have already red many posts about the subject, some of these works, but only on some devices. For example it works on my Nexus 4, Nexus 5 with cyaogenmod, but not on my Xiaomi Mi2s (jelly beam 4.1.1) I tried setting it sticky, using alarm, and broadcast receiver on destroy. But neither of them worked out. When I kill the application it never wake up again. But on the same device Whatsapp works perfectly, and even if I kill it, it wake up again.. Is there any way to do it without use GCM? Some of the link I already looked up: How to restart a killed service automatically? Service that

Broadcast Intent on contact added/edited/changed - android

随声附和 提交于 2019-11-29 12:44:16
In my app, I have a service in which I want to listen for any changes in contacts i.e., when any contact is added or edited in the native contacts app or through any other app. Is there any broadcast intent which I can register to for this purpose? Or is there any other way to achieve this? atomman Found someone with a similar problem, his solution was using RawContacts. Broadcast on contact add/change? http://developer.android.com/reference/android/provider/ContactsContract.RawContacts.html 来源: https://stackoverflow.com/questions/14038956/broadcast-intent-on-contact-added-edited-changed

Android Notification with FCM - Who started the FirebaseMessagingService?

戏子无情 提交于 2019-11-29 12:38:51
问题 According to the set up guide here, in a sample app, A) I created a class that extends firebase services class. B) I put these classes in the AndroidManifest.xml A) Java Class public class MyFirebaseMessagingService extends FirebaseMessagingService { @Override public void onMessageReceived(RemoteMessage remoteMessage) { //a) What's the life cycle of the service? How can I ensure this method is getting called? //b) If the service is killed at some point, will system restart it on receiving new

Are their any negatives impacts of launching two continues services at the same time? What are some alternatives if so?

旧城冷巷雨未停 提交于 2019-11-29 12:22:07
I am planning on having an activity with two check boxes. I want to do some tasks when the screen is off in the background continuously based on what the user check marks. final CheckBox checkBox = (CheckBox) findViewById(R.id.checkbox_id); if ( checkBox1.isChecked() && myServiceIsntRunning() ) { startService(myService1.class) if ( checkBox2.isChecked() && myService2IsntRunning() ) { startService(myService2.class) } If both the checkmarks are checked, I wan't both tasks to constantly run in the background forever using this method. Is there any harm in launching both services at once? There

Single Notification for multiple Foreground Services using startForeground() call

北城余情 提交于 2019-11-29 12:06:07
问题 I have an app that has two services. One is for showing UI for floating (overlay) on other apps using WindowManager . The other is for Location Tracking using GooglePlayAPI . My app always runs these services. I want these services not to be killed by the OS. So I call Service.startForeground() . However there are two notifications in the notification drawer. Is there a way to use a single notification for both services? 回答1: Yes, it is possible. If we take a look at Service.startForeground()

Prevent multiple copies of an Android service

北城余情 提交于 2019-11-29 12:03:46
问题 The doco for startService states "If this service is not already running, it will be instantiated and started (creating a process for it if needed); if it is running then it remains running." I'm finding that each call to startService appears to be starting a separate instance of the service, in that the work that the service is doing (in my test case, trivially writing to a new log file) is being done again for each call. I'm trying to detect the service by looping through ActivityManager...

Start two services in foreground?

a 夏天 提交于 2019-11-29 12:03:39
In an effort to keep my services alive, can I have more than one service in foreground? I am starting two services at once, and I don't want any of them to be destroyed. So, after reading for hours, I found the solution is to return START_STICKY and use startForeground(...) on my service. But, I have two services, so can I have them both be in the foreground, and both never be destroyed? Trinimon There are several aspects to consider. First of all: if you have two services in foreground, you have to have two notifications as well. This is considered as a security feature (check for instance