android-service

One-minute periodic service

爷,独闯天下 提交于 2019-12-07 17:43:50
问题 What's the correct way to perform a periodic task? My implementation does not seem to work properly: when the screen is on and I am using the phone the service method is ran perfectly in time. However when the phone is locked the service is ran at very large and random intervals (e.g: 10:30 10:32 10:45 10:46 10:49 11:00...) Here is the code: MAIN SERVICE CLASS: @Override public void onCreate() { pm = (PowerManager) getSystemService(Context.POWER_SERVICE); mNM = (NotificationManager

onTaskRemoved called after onCreate in started service on swipe-out from recent app list

我的未来我决定 提交于 2019-12-07 15:38:11
问题 I have a service started from an Activity, the service is running fine onCreate , onStartCommand called properly. In settings-->running app its showing 1 process and 1 service . Now when I swipe out my application from apps recent list. The service recreates, In settings-->running app it shows 0 process and 1 service restarting... And onCreate , onStartCommand , onTaskRemoved called. Now the issue is in one app onTaskRemoved called immediately after swiping app out then onCreate called, and

Starting Android IntentService with explicit intent NullPointerException

﹥>﹥吖頭↗ 提交于 2019-12-07 15:33:02
问题 I'm trying to start an IntentService from a clickhandler in my main activity. I'm studying Intents right now but don't quite get it yet. I'm not sure how I'm supposed to instantiate my intent here and pass it to startService . I don't know why I have to do such a thing, the Intent will not be used within my service, that I know of. I don't know how to debug this problem. From the click callback: this.commute = new Commute(); locationService = new LocationService(); locationService.setCommute

Android Service (“startService & stopService”) and Play/Stop Button in One

守給你的承諾、 提交于 2019-12-07 15:27:12
问题 I am developing an Android app and I need to make one button which will be a Play/Stop button for Android Service playing and stopping. Play button is for startActivity(); Stop button is for stopActivity(); How do I make this? 回答1: You just need to declare a flag variable and declare body of onclick() based on flag value like this. public class ServiceActivity extends Activity { Button play; int button_status=1; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate

want to run and stop service with activity android

别等时光非礼了梦想. 提交于 2019-12-07 14:22:40
问题 I am wondering if i can do this, i want to implement a service that will be called when activity launches and should run at regular intervals, and when i stop the activity by closing or pressing back the service should stop and alarm manager should not invoke service before the activity relaunches. One more thing i want to send some data on which service can operate and give results back to activity. currently i am doing like this..... class MyService extends Service{ } class MyScheduler

Start service in another package without Intent filter

自作多情 提交于 2019-12-07 14:16:23
问题 Is there a way to start an Android Service defined in another package without using the Intent-Filter tag in the manifest file? For some reason I would not be able to update the manifest file of the app that contains the Service. 回答1: If you know the exact package name and service name you can create an Intent with that. The service still needs to be declared in the other manifest though. Intent intent = new Intent(); intent.setClassName("com.example.otherapplication", "com.example

how to correctly use android.test.ServiceTestCase?

心已入冬 提交于 2019-12-07 12:49:44
问题 My app is a Service that runs in /system/app com.abc.def.MyApp Trying to write unit tests for it, I get this error in the logcat while running. I/TestGrouping( 5647): TestCase class com.abc.def.test.MyAppTest is missing a public constructor with no parameters or a single String parameter - skipping command used: D:\tmp_install>adb shell am instrument -w com.abc.def.test/android.test.InstrumentationTestRunner WARNING: linker: memtrack.jacinto6.so: unused DT entry: type 0xf arg 0x115 WARNING:

Service with AsyncTask

ε祈祈猫儿з 提交于 2019-12-07 12:32:25
问题 I have heard that it isnt good to have an async task in a service. Is it really necessary for an AsyncTask or just onStartCommand() ? I am wondering because I have a Service with an AsyncTask that is launched by an alarm. And it launches the Service more than once; it's only supposed to launch once. Could this be the reason? EDIT: Here is how i set up the alarm. String alarm = Context.ALARM_SERVICE; AlarmManager am = (AlarmManager)getSystemService(alarm); Intent Aintent = new Intent("REFRESH

onCreate of android service not called

橙三吉。 提交于 2019-12-07 10:28:12
问题 I want to start a service in a static way. So from my activity I call SpeechActivationService.makeStartServiceIntent( this.getApplicationContext(), "WordActivator"); Here is the actual class that extends from service class http://dpaste.com/hold/928115/ As you can see there are several log points, e.g. in the onCreate method. This is not logged. Only if I put log text in makeStartServiceIntent method it appears, however not in the onCreate method. Here's the makeStartServiceIntent method:

peekService() returns null even though the service is running, if the service is restarted by the system after OOM kill

杀马特。学长 韩版系。学妹 提交于 2019-12-07 08:20:28
问题 I'm starting a service using startService(new Intent(this, RelayService.class)); and then the service starts an alarm using AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(this, SyncAlarmReceiver.class); PendingIntent pi = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + SYNC_EVERY_MS, SYNC_EVERY_MS, pi); and then