i have a service with this code
public class service extends Service{
private AlarmManager alarm;
private PendingIntent addData, sendData, fullData;
// run on another Thread to avoid crash
private Handler mHandler = new Handler();
@Override
public IBinder onBind(Intent intent) {
retu null;
}
@Override
public void onDestroy() {
if(!App.User.GetUserCode().equals("")){
App.DataFrame.InfoLog("Location is tued OFF");
App.DataFrame.Off();
mHandler.postDelayed(new Ruable() {
@Override
public void run() {
stopAlarm();
Intent stoploc = new Intent(service.this, LocationProvider.class);
service.this.stopService(stoploc);
stopForeground(true);
stopSelf();
App.User.Logout();
App.Toast("Stopping Service");
}
}, 1000);
}else{
stopAlarm();
Intent stoploc = new Intent(service.this, LocationProvider.class);
service.this.stopService(stoploc);
stopForeground(true);
stopSelf();
App.Toast("Stopping Service");
}
super.onDestroy();
}
public void stopAlarm(){
alarm.cancel(addData);
alarm.cancel(sendData);
alarm.cancel(fullData);
}
@Override
public void onCreate() {
App.Toast("Starting Services");
alarm = (AlarmManager) getSystemService(App.GetContext().ALARM_SERVICE);
Intent intent = new Intent(this, CoorReceiver.class);
addData = PendingIntent.getBroadcast(this, 0, intent.putExtra("Code", 0), PendingIntent.FLAG_UPDATE_CURRENT);
sendData = PendingIntent.getBroadcast(this, 1, intent.putExtra("Code", 1), PendingIntent.FLAG_UPDATE_CURRENT);
fullData = PendingIntent.getBroadcast(this, 2, intent.putExtra("Code", 2), PendingIntent.FLAG_UPDATE_CURRENT);
alarm.setInexactRepeating(AlarmManager.RTC_WAKEUP, 15000, 15000, addData);
alarm.setInexactRepeating(AlarmManager.RTC_WAKEUP, 300000, 300000, sendData);
alarm.setInexactRepeating(AlarmManager.RTC_WAKEUP, 600000, 600000, fullData);
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Intent intent2 = new Intent(this, MainActivity.class);
intent2.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendIntent = PendingIntent.getActivity(this, 0, intent2, 0);
Notification noti = new Notification.Builder(getApplicationContext())
.setContentTitle("Imagine")
.setContentText("Service is Ruing")
.setSmallIcon(R.drawable.ic_launcher)
.setContentIntent(pendIntent)
.build();
startForeground(1234, noti);
retu START_STICKY;
}
}
and a broadcastreceiver
public class CoorReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
int code = intent.getIntExtra("Code", 0);
if(code == 0){
App.DataFrame.AddPresentCoordinate();
App.Toast("Get");
try{
if(App.Location.IsNetworkEnabled() == false && App.Location.IsGPSEnabled() == false){
context.stopService(new Intent(context, service.class));
}
}catch (RuntimeException e){
App.DataFrame.ErrorLog("Checking GPS Status", e.getMessage());
}
}else if(code == 1){
App.DataFrame.SendValidData();
App.Toast("Send");
}else if(code == 2){
App.DataFrame.SendFullData();
App.Toast("Full");
}
}
}
when I plug my phone to my PC via usb and do debugging with a few breakpoint, the alarm will call receiver every 15s, 5min, and 10min
but when I generate the signed apk(release or debug), the alarm won't call the receiver
does anyone have same problem? or any solution?
