android-service

Starting LocationManager as Service Android

柔情痞子 提交于 2019-12-03 07:54:13
What I'm attempting to do is when receiving a c2dm message, start a service that asks for location for 'x' amount of time and then hands that location off to our server. The c2dm message starts the service correctly, and the GPS location turns on, but it never updates. It just sits there for the length of time I specify (currently 12 seconds) in the thread and does nothing. I'm using the exact same code somewhere else in my app (not as a service) and it works perfectly. What am I doing wrong? This starts the service when receiving a c2dm message. context.startService(new Intent(context,

How to create an android app that activates on shake events when screen locked? [closed]

老子叫甜甜 提交于 2019-12-03 07:49:48
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . I want to create an app that **starts the Main activity whenever the device shakes, even when screen locked. Can anyone explain how to do that? I have an idea that it requires to create a service that runs in background, but I am struggling with actual coding and don't know how to do it. 回答1: To create an app

Service not being created (or connecting) after bindService()

廉价感情. 提交于 2019-12-03 07:22:29
I have this simple service that broadcasts the current location of the user. I want to use the binding mechanism just to control the service life-cycle, but the service is just not starting. What did I do wrong? public class GPSActivity extends ListActivity { ... protected void onResume() { super.onResume(); Log.i("Service", "Service bound"); Intent intent = new Intent(this, LocationService.class); bindService(intent, service_connection , Context.BIND_AUTO_CREATE); } protected void onPause() { if (dataUpdateReceiver!=null) unregisterReceiver(dataUpdateReceiver); unbindService(service

Bind service to activity or fragment?

ⅰ亾dé卋堺 提交于 2019-12-03 06:55:38
问题 I am working on a music player app. I have a main activity which has multiple fragments, each displaying songs on the device album wise, artist wise etc.. I have a music service which handles all the playback and other stuff. What I'm confused about is the binding of this service with various fragments I have. Right now I'm binding the main activity and each fragment individually with the service and its working pretty much fine. But I was wondering if this is really the best practice? Is

Android - How is it possible, that a service keeps running after the Activity has been shut down?

浪子不回头ぞ 提交于 2019-12-03 06:55:07
I am a bit confused about how services function, notably these two things: From http://developer.android.com/guide/topics/fundamentals/services.html : A service is "started" when an application component (such as an activity) starts it by calling startService(). Once started, a service can run in the background indefinitely, even if the component that started it is destroyed. and: Caution: A service runs in the main thread of its hosting process—the service does not create its own thread and does not run in a separate process (unless you specify otherwise). My questions: How is it possible for

Unable to start service [service name] with null

旧城冷巷雨未停 提交于 2019-12-03 06:51:03
问题 i recently coded a Android Widget and tested it on Emulator as well as my Galaxy S , it worked fine on both, after i posted the same to android market now i am getting some error reports. i am stating a service in the onUpdate of Widget Class like this: if (appWidgetIds != null) { final int N = appWidgetIds.length; // Perform this loop procedure for each App Widget that belongs to // this // provider for (int i = 0; i < N; i++) { // Start Service for each instance int appWidgetId =

get Activity's reference from a Service

╄→гoц情女王★ 提交于 2019-12-03 06:49:20
I need to get a reference to the main Activity from a Service. This is my design: MainActivity.java public class MainActivity extends Activity{ private Intent myIntent; onCreate(){ myIntent=new Intent(MainActivity.this, MyService.class); btnStart.setOnClickListener(new OnClickListener(){ public void onClick(View V){ startService(myIntent); }); }} MyService.java class MyService extends Service{ public IBinder onBind(Intent intent) { return null; } onCreate(){ //Here I need to have a MainActivity reference //to pass it to another object } } How can I do this? [EDIT] Thanks to all for the answers

Detecting Android L Battery Saver

主宰稳场 提交于 2019-12-03 06:16:49
One of the new features of Android L is a battery saver that kicks in at 15%. Is there some way to detect when this is active, so my app will respond correctly? http://www.technobuffalo.com/2014/07/02/android-l-project-volta-battery-life/ I would like my app to get a callback from the operating system when the this mode is active so I can stop background services. If there is no callback, I could make a background process query for the battery level, but that seems wasteful. I also do not want to hard-code a 15% level into the app, because I assume this level will be configurable. Is there a

Foreground service gets killed on performing internet related operations

大憨熊 提交于 2019-12-03 06:02:41
UPDATE: Previously I couldn't find a well defined pattern as to when my foreground service was being killed. After more debugging with the devices (doesn't happen on all) on which this was happening I found. 1.) A lot of times when I open chrome to load a website the foreground service gets killed. Sometimes even when I am using whatsapp this happens. 2.) There are no exceptions and the stacktrace doesn't show anything useful. Original Question below: There are many such questions on StackOverflow but the answers so far that I have read mostly say that it is upto Android and we don't have 100%

Android Notification with FCM - Who started the FirebaseMessagingService?

≯℡__Kan透↙ 提交于 2019-12-03 05:57:24
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 messages? Log.d(TAG, "From: " + remoteMessage.getFrom()); } } B) AndroidManifest.xml <service android