android-intentservice

setRepeating of AlarmManager not respond within the time indicated

自古美人都是妖i 提交于 2019-12-02 12:06:58
AlarmManager should be repeated every 1 minute, but repeated every 1, 2, 3 or 4 minutes. Since the application I throw AlarmManager public class PacienteApp extends Application { @Override public void onCreate() { AlarmManager gps = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE); Intent i = new Intent(this, GpsReceiver.class); PendingIntent pending = PendingIntent.getBroadcast(this, 0, i, 0); gps.setRepeating(AlarmManager.RTC, System.currentTimeMillis(), 1000 * 60, pending); } } Since BroadcastReceiver call a IntentService. public class GpsReceiver extends BroadcastReceiver {

Notification Android : Don't show notification when app is open?

拟墨画扇 提交于 2019-12-02 09:38:54
I'm working on a project and I use Intent Service with wakefulBroadcastReceiver to schedule alarm and send notification. There are no problems this far. But I want when I open my app, it don't displaying notification again. Please any idea for this problem?. In your notification receiver when you receive the notification you can check whether the app is in background or not and take a decision of showing the notification accordingly. Here's a code to check whether the app is in background or not. public class MyGcmPushReceiver extends GcmListenerService { /** * Called when message is received.

Android calling IntentService class from a Service Class

人走茶凉 提交于 2019-12-02 09:32:19
Can we call IntentService class from a running Service class . Intent myintentservice = new Intent(this, MyIntentService.class); startService(myintentservice); I using above lines of code in service class to start IntentService class. But then I get following error:- Process: objectdistance.ankeshkjaisansaria.ram.sita.cameratag, PID: 21823 java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference at android.content.ComponentName.<init>(ComponentName.java:77) at android.content.Intent.<init>(Intent

Stop service in an activity

寵の児 提交于 2019-12-02 04:41:28
问题 I'm using following code to stop my service Intent intent = new Intent(MainActivity.this, UsageRecorderService.class); stopService(intent); And this is my service that works indefinitely public class UsageRecorderService extends IntentService { public UsageRecorderService() { super("UsageRecorder"); } @Override protected void onHandleIntent(Intent intent) { while (true) { UsageRecorder.recordUsages(this, false); SystemClock.sleep(10000); } } } Why does not stop my service? 回答1: This code

Stop service in an activity

六眼飞鱼酱① 提交于 2019-12-01 22:59:27
I'm using following code to stop my service Intent intent = new Intent(MainActivity.this, UsageRecorderService.class); stopService(intent); And this is my service that works indefinitely public class UsageRecorderService extends IntentService { public UsageRecorderService() { super("UsageRecorder"); } @Override protected void onHandleIntent(Intent intent) { while (true) { UsageRecorder.recordUsages(this, false); SystemClock.sleep(10000); } } } Why does not stop my service? This code would work public class UsageRecorderService extends IntentService { private boolean mStop = false; public

Unable to find explicit activity class {}; have you declared this activity in your AndroidManifest.xml

旧时模样 提交于 2019-12-01 19:01:36
I'm trying unzip some files in background, so I use IntentService like in google's tutorial. My service class declared in AndroidManifest like this: <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.osmdroid"> <uses-sdk android:minSdkVersion="16" android:targetSdkVersion="21" /> <application android:configChanges="orientation|screenSize|keyboardHidden" android:hardwareAccelerated="true" android:icon="@drawable/ecn_icon" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".MapActivity" android:icon="@drawable/ecn_icon"

handler.postDelayed is not working in onHandleIntent method of IntentService

隐身守侯 提交于 2019-12-01 17:52:21
final Handler handler = new Handler(); LOG.d("delay"); handler.postDelayed(new Runnable() { @Override public void run() { LOG.d("notify!"); //calling some methods here } }, 2000); The "delay" does shows in the log, but not others at all. And the method called in the run() is not called at all also. Can anyone help explain why this happens, am I doing anything wrong? The class that has this code extends IntentService, will this be a problem? ============================ UPDATE: I put this code in the class that extends IntentService . The only place I found it worked was in the constructor. But

handler.postDelayed is not working in onHandleIntent method of IntentService

試著忘記壹切 提交于 2019-12-01 16:38:40
问题 final Handler handler = new Handler(); LOG.d("delay"); handler.postDelayed(new Runnable() { @Override public void run() { LOG.d("notify!"); //calling some methods here } }, 2000); The "delay" does shows in the log, but not others at all. And the method called in the run() is not called at all also. Can anyone help explain why this happens, am I doing anything wrong? The class that has this code extends IntentService, will this be a problem? ============================ UPDATE: I put this code

Problems in Calling AsyncTask from IntentService

柔情痞子 提交于 2019-11-30 17:17:20
问题 I have created IntentService class and performing asyncTask but getting exception when onPreExecute() is called at this code line pDialog.show(); AsyncHandlerService Class --- public class AsyncHandlerService extends IntentService{ ProgressDialog pDialog; HttpPost post; HttpResponse response; Context ctx; public AsyncHandlerService() { super("AsyncHandlerService"); ctx = this; } @Override protected void onHandleIntent(Intent intent) { new LoadDeviceInfo().execute(); } class LoadDeviceInfo

Realm `access from incorrect thread` error when using shared code between IntentService and AsyncTask (Android)

人盡茶涼 提交于 2019-11-30 08:38:01
I have some code that downloads a "Current" object's JSON. But this same code needs to be called by an IntentService whenever an alarm goes off (when the app is not running any UI), and also by an AsyncTask while the app is running. However, I got an error saying Realm access from incorrect thread. Realm objects can only be accessed on the thread they were created. However, I do not understand how or why this stack trace got on a different thread. I was able to get rid of the error by copying all the shared code and sticking it directly into DownloadDealService's onHandleIntent method, but it