Broadcast Receiver is not working when application is removed from background?










3















I am trying to run this code in my mobile app, but it is not running and also giving no error. I have tried printing log also, but it is not showing anything in logcat. This problem only occur in Oreo and run well in all other Android versions, also runs well when application is in background.



public class MainActivity extends AppCompatActivity 

AlarmManager am;
TimeAlarm timeAlarm;
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
setOneTimeAlarm();


public void setOneTimeAlarm()
Intent intent = new Intent(this, TimeAlarm.class);

PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);

am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (5 * 1000), pendingIntent);


public void setRepeatingAlarm()
Intent intent = new Intent(this, TimeAlarm.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), (5 * 1000), pendingIntent);


@Override
protected void onDestroy()
super.onDestroy();
Log.d("ondestroy","ondestroy");



@Override
protected void onStart()
super.onStart();
Log.d("onstart","onstart");

IntentFilter intentFilter=new IntentFilter("my.custom.action.tag.fordemo");
intentFilter.addCategory(Intent.CATEGORY_DEFAULT);
registerReceiver(timeAlarm,intentFilter);




Code Of broadcast receiver, when I have removed the application from background it stopped working.



public class TimeAlarm extends BroadcastReceiver 

NotificationManager nm;
String channelId = "channel-01";
String channelName = "Channel Name";
int importance = NotificationManager.IMPORTANCE_HIGH;

@RequiresApi(api = Build.VERSION_CODES.O)
@Override
public void onReceive(Context context, Intent intent)
nm = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
NotificationChannel mChannel = new NotificationChannel(
channelId, channelName, importance);
nm.createNotificationChannel(mChannel);
else


CharSequence from = "Nithin";
CharSequence message = "Crazy About Android...";
PendingIntent contentIntent =
PendingIntent.getActivity(context, 0, new Intent(), 0);
//Notification notif = new Notification(R.drawable.logo,
"Crazy About Android...", System.currentTimeMillis());
NotificationCompat.Builder notification = new
NotificationCompat.Builder(context.getApplicationContext());
// notification.setContentIntent(pintent);
notification.setTicker(from).setSubText(from).setSmallIcon(R.drawable.logo);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
notification.setChannelId(channelId);


Notification notification1 = notification.build();
notif.setLatestEventInfo(context, from, message,contentIntent);
nm.notify(1, notification1);











share|improve this question
























  • Did you have addredd permissions in your manifest?

    – Alesandro Giordano
    Nov 13 '18 at 10:19











  • about which permission u r asking

    – jyoti sharma
    Nov 14 '18 at 10:53











  • I'll write them into an answer

    – Alesandro Giordano
    Nov 14 '18 at 10:58















3















I am trying to run this code in my mobile app, but it is not running and also giving no error. I have tried printing log also, but it is not showing anything in logcat. This problem only occur in Oreo and run well in all other Android versions, also runs well when application is in background.



public class MainActivity extends AppCompatActivity 

AlarmManager am;
TimeAlarm timeAlarm;
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
setOneTimeAlarm();


public void setOneTimeAlarm()
Intent intent = new Intent(this, TimeAlarm.class);

PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);

am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (5 * 1000), pendingIntent);


public void setRepeatingAlarm()
Intent intent = new Intent(this, TimeAlarm.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), (5 * 1000), pendingIntent);


@Override
protected void onDestroy()
super.onDestroy();
Log.d("ondestroy","ondestroy");



@Override
protected void onStart()
super.onStart();
Log.d("onstart","onstart");

IntentFilter intentFilter=new IntentFilter("my.custom.action.tag.fordemo");
intentFilter.addCategory(Intent.CATEGORY_DEFAULT);
registerReceiver(timeAlarm,intentFilter);




Code Of broadcast receiver, when I have removed the application from background it stopped working.



public class TimeAlarm extends BroadcastReceiver 

NotificationManager nm;
String channelId = "channel-01";
String channelName = "Channel Name";
int importance = NotificationManager.IMPORTANCE_HIGH;

@RequiresApi(api = Build.VERSION_CODES.O)
@Override
public void onReceive(Context context, Intent intent)
nm = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
NotificationChannel mChannel = new NotificationChannel(
channelId, channelName, importance);
nm.createNotificationChannel(mChannel);
else


CharSequence from = "Nithin";
CharSequence message = "Crazy About Android...";
PendingIntent contentIntent =
PendingIntent.getActivity(context, 0, new Intent(), 0);
//Notification notif = new Notification(R.drawable.logo,
"Crazy About Android...", System.currentTimeMillis());
NotificationCompat.Builder notification = new
NotificationCompat.Builder(context.getApplicationContext());
// notification.setContentIntent(pintent);
notification.setTicker(from).setSubText(from).setSmallIcon(R.drawable.logo);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
notification.setChannelId(channelId);


Notification notification1 = notification.build();
notif.setLatestEventInfo(context, from, message,contentIntent);
nm.notify(1, notification1);











share|improve this question
























  • Did you have addredd permissions in your manifest?

    – Alesandro Giordano
    Nov 13 '18 at 10:19











  • about which permission u r asking

    – jyoti sharma
    Nov 14 '18 at 10:53











  • I'll write them into an answer

    – Alesandro Giordano
    Nov 14 '18 at 10:58













3












3








3








I am trying to run this code in my mobile app, but it is not running and also giving no error. I have tried printing log also, but it is not showing anything in logcat. This problem only occur in Oreo and run well in all other Android versions, also runs well when application is in background.



public class MainActivity extends AppCompatActivity 

AlarmManager am;
TimeAlarm timeAlarm;
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
setOneTimeAlarm();


public void setOneTimeAlarm()
Intent intent = new Intent(this, TimeAlarm.class);

PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);

am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (5 * 1000), pendingIntent);


public void setRepeatingAlarm()
Intent intent = new Intent(this, TimeAlarm.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), (5 * 1000), pendingIntent);


@Override
protected void onDestroy()
super.onDestroy();
Log.d("ondestroy","ondestroy");



@Override
protected void onStart()
super.onStart();
Log.d("onstart","onstart");

IntentFilter intentFilter=new IntentFilter("my.custom.action.tag.fordemo");
intentFilter.addCategory(Intent.CATEGORY_DEFAULT);
registerReceiver(timeAlarm,intentFilter);




Code Of broadcast receiver, when I have removed the application from background it stopped working.



public class TimeAlarm extends BroadcastReceiver 

NotificationManager nm;
String channelId = "channel-01";
String channelName = "Channel Name";
int importance = NotificationManager.IMPORTANCE_HIGH;

@RequiresApi(api = Build.VERSION_CODES.O)
@Override
public void onReceive(Context context, Intent intent)
nm = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
NotificationChannel mChannel = new NotificationChannel(
channelId, channelName, importance);
nm.createNotificationChannel(mChannel);
else


CharSequence from = "Nithin";
CharSequence message = "Crazy About Android...";
PendingIntent contentIntent =
PendingIntent.getActivity(context, 0, new Intent(), 0);
//Notification notif = new Notification(R.drawable.logo,
"Crazy About Android...", System.currentTimeMillis());
NotificationCompat.Builder notification = new
NotificationCompat.Builder(context.getApplicationContext());
// notification.setContentIntent(pintent);
notification.setTicker(from).setSubText(from).setSmallIcon(R.drawable.logo);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
notification.setChannelId(channelId);


Notification notification1 = notification.build();
notif.setLatestEventInfo(context, from, message,contentIntent);
nm.notify(1, notification1);











share|improve this question
















I am trying to run this code in my mobile app, but it is not running and also giving no error. I have tried printing log also, but it is not showing anything in logcat. This problem only occur in Oreo and run well in all other Android versions, also runs well when application is in background.



public class MainActivity extends AppCompatActivity 

AlarmManager am;
TimeAlarm timeAlarm;
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
setOneTimeAlarm();


public void setOneTimeAlarm()
Intent intent = new Intent(this, TimeAlarm.class);

PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);

am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (5 * 1000), pendingIntent);


public void setRepeatingAlarm()
Intent intent = new Intent(this, TimeAlarm.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), (5 * 1000), pendingIntent);


@Override
protected void onDestroy()
super.onDestroy();
Log.d("ondestroy","ondestroy");



@Override
protected void onStart()
super.onStart();
Log.d("onstart","onstart");

IntentFilter intentFilter=new IntentFilter("my.custom.action.tag.fordemo");
intentFilter.addCategory(Intent.CATEGORY_DEFAULT);
registerReceiver(timeAlarm,intentFilter);




Code Of broadcast receiver, when I have removed the application from background it stopped working.



public class TimeAlarm extends BroadcastReceiver 

NotificationManager nm;
String channelId = "channel-01";
String channelName = "Channel Name";
int importance = NotificationManager.IMPORTANCE_HIGH;

@RequiresApi(api = Build.VERSION_CODES.O)
@Override
public void onReceive(Context context, Intent intent)
nm = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
NotificationChannel mChannel = new NotificationChannel(
channelId, channelName, importance);
nm.createNotificationChannel(mChannel);
else


CharSequence from = "Nithin";
CharSequence message = "Crazy About Android...";
PendingIntent contentIntent =
PendingIntent.getActivity(context, 0, new Intent(), 0);
//Notification notif = new Notification(R.drawable.logo,
"Crazy About Android...", System.currentTimeMillis());
NotificationCompat.Builder notification = new
NotificationCompat.Builder(context.getApplicationContext());
// notification.setContentIntent(pintent);
notification.setTicker(from).setSubText(from).setSmallIcon(R.drawable.logo);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
notification.setChannelId(channelId);


Notification notification1 = notification.build();
notif.setLatestEventInfo(context, from, message,contentIntent);
nm.notify(1, notification1);








java android android-8.0-oreo






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 12:35









Spara

3,06521441




3,06521441










asked Nov 12 '18 at 13:48









jyoti sharmajyoti sharma

163




163












  • Did you have addredd permissions in your manifest?

    – Alesandro Giordano
    Nov 13 '18 at 10:19











  • about which permission u r asking

    – jyoti sharma
    Nov 14 '18 at 10:53











  • I'll write them into an answer

    – Alesandro Giordano
    Nov 14 '18 at 10:58

















  • Did you have addredd permissions in your manifest?

    – Alesandro Giordano
    Nov 13 '18 at 10:19











  • about which permission u r asking

    – jyoti sharma
    Nov 14 '18 at 10:53











  • I'll write them into an answer

    – Alesandro Giordano
    Nov 14 '18 at 10:58
















Did you have addredd permissions in your manifest?

– Alesandro Giordano
Nov 13 '18 at 10:19





Did you have addredd permissions in your manifest?

– Alesandro Giordano
Nov 13 '18 at 10:19













about which permission u r asking

– jyoti sharma
Nov 14 '18 at 10:53





about which permission u r asking

– jyoti sharma
Nov 14 '18 at 10:53













I'll write them into an answer

– Alesandro Giordano
Nov 14 '18 at 10:58





I'll write them into an answer

– Alesandro Giordano
Nov 14 '18 at 10:58












3 Answers
3






active

oldest

votes


















0














It shouldn't be working when in the background on any version of the OS. You're registering the receiver in onStart, then unregistering in onStop. That means the receiver, to the OS, does not exist after onStop is processed. If you're seeing it work on other versions of the OS, that's actually a bug.






share|improve this answer























  • i removed code from onstop..but still its not working.And i also change the code

    – jyoti sharma
    Nov 13 '18 at 5:35



















0














Sure, your broadcast is killed when your application is closed. If you dont unregisterReceiver in onStop/onDestroyed, you will have a leak issue. To avoid it,
you should implement a Service (and call registerReceiver(timeAlarm,intentFilter); in your service) which runs in the background even when your application is closed.



P/s: remember to startForeground to prevent service from being killed by system in Android 8.0 or above.






share|improve this answer























  • I don't understand can u explain this by example....or send screenshots.... if used it anywhere

    – jyoti sharma
    Nov 13 '18 at 14:42











  • please sir....when u get time ...reply me

    – jyoti sharma
    Nov 14 '18 at 10:51











  • @jyotisharma you should use Service to register your intentFilter instead of registering in your Application. Here's the Service tutorial you should take a look at: vogella.com/tutorials/AndroidServices/article.html

    – Kingfisher Phuoc
    Nov 14 '18 at 18:49



















0














You have to add alarm permission in your manifest



<uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission>


And also To register your broadcast



 <receiver
android:name=".broadcast.ServiceBroadcast"
android:enabled="true"
android:exported="true"
android:label="RestartServices">
<intent-filter>
<action android:name="restart_services"/>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>





share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53263566%2fbroadcast-receiver-is-not-working-when-application-is-removed-from-background%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    It shouldn't be working when in the background on any version of the OS. You're registering the receiver in onStart, then unregistering in onStop. That means the receiver, to the OS, does not exist after onStop is processed. If you're seeing it work on other versions of the OS, that's actually a bug.






    share|improve this answer























    • i removed code from onstop..but still its not working.And i also change the code

      – jyoti sharma
      Nov 13 '18 at 5:35
















    0














    It shouldn't be working when in the background on any version of the OS. You're registering the receiver in onStart, then unregistering in onStop. That means the receiver, to the OS, does not exist after onStop is processed. If you're seeing it work on other versions of the OS, that's actually a bug.






    share|improve this answer























    • i removed code from onstop..but still its not working.And i also change the code

      – jyoti sharma
      Nov 13 '18 at 5:35














    0












    0








    0







    It shouldn't be working when in the background on any version of the OS. You're registering the receiver in onStart, then unregistering in onStop. That means the receiver, to the OS, does not exist after onStop is processed. If you're seeing it work on other versions of the OS, that's actually a bug.






    share|improve this answer













    It shouldn't be working when in the background on any version of the OS. You're registering the receiver in onStart, then unregistering in onStop. That means the receiver, to the OS, does not exist after onStop is processed. If you're seeing it work on other versions of the OS, that's actually a bug.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 12 '18 at 13:56









    Gabe SechanGabe Sechan

    1




    1












    • i removed code from onstop..but still its not working.And i also change the code

      – jyoti sharma
      Nov 13 '18 at 5:35


















    • i removed code from onstop..but still its not working.And i also change the code

      – jyoti sharma
      Nov 13 '18 at 5:35

















    i removed code from onstop..but still its not working.And i also change the code

    – jyoti sharma
    Nov 13 '18 at 5:35






    i removed code from onstop..but still its not working.And i also change the code

    – jyoti sharma
    Nov 13 '18 at 5:35














    0














    Sure, your broadcast is killed when your application is closed. If you dont unregisterReceiver in onStop/onDestroyed, you will have a leak issue. To avoid it,
    you should implement a Service (and call registerReceiver(timeAlarm,intentFilter); in your service) which runs in the background even when your application is closed.



    P/s: remember to startForeground to prevent service from being killed by system in Android 8.0 or above.






    share|improve this answer























    • I don't understand can u explain this by example....or send screenshots.... if used it anywhere

      – jyoti sharma
      Nov 13 '18 at 14:42











    • please sir....when u get time ...reply me

      – jyoti sharma
      Nov 14 '18 at 10:51











    • @jyotisharma you should use Service to register your intentFilter instead of registering in your Application. Here's the Service tutorial you should take a look at: vogella.com/tutorials/AndroidServices/article.html

      – Kingfisher Phuoc
      Nov 14 '18 at 18:49
















    0














    Sure, your broadcast is killed when your application is closed. If you dont unregisterReceiver in onStop/onDestroyed, you will have a leak issue. To avoid it,
    you should implement a Service (and call registerReceiver(timeAlarm,intentFilter); in your service) which runs in the background even when your application is closed.



    P/s: remember to startForeground to prevent service from being killed by system in Android 8.0 or above.






    share|improve this answer























    • I don't understand can u explain this by example....or send screenshots.... if used it anywhere

      – jyoti sharma
      Nov 13 '18 at 14:42











    • please sir....when u get time ...reply me

      – jyoti sharma
      Nov 14 '18 at 10:51











    • @jyotisharma you should use Service to register your intentFilter instead of registering in your Application. Here's the Service tutorial you should take a look at: vogella.com/tutorials/AndroidServices/article.html

      – Kingfisher Phuoc
      Nov 14 '18 at 18:49














    0












    0








    0







    Sure, your broadcast is killed when your application is closed. If you dont unregisterReceiver in onStop/onDestroyed, you will have a leak issue. To avoid it,
    you should implement a Service (and call registerReceiver(timeAlarm,intentFilter); in your service) which runs in the background even when your application is closed.



    P/s: remember to startForeground to prevent service from being killed by system in Android 8.0 or above.






    share|improve this answer













    Sure, your broadcast is killed when your application is closed. If you dont unregisterReceiver in onStop/onDestroyed, you will have a leak issue. To avoid it,
    you should implement a Service (and call registerReceiver(timeAlarm,intentFilter); in your service) which runs in the background even when your application is closed.



    P/s: remember to startForeground to prevent service from being killed by system in Android 8.0 or above.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 13 '18 at 9:56









    Kingfisher PhuocKingfisher Phuoc

    5,25873769




    5,25873769












    • I don't understand can u explain this by example....or send screenshots.... if used it anywhere

      – jyoti sharma
      Nov 13 '18 at 14:42











    • please sir....when u get time ...reply me

      – jyoti sharma
      Nov 14 '18 at 10:51











    • @jyotisharma you should use Service to register your intentFilter instead of registering in your Application. Here's the Service tutorial you should take a look at: vogella.com/tutorials/AndroidServices/article.html

      – Kingfisher Phuoc
      Nov 14 '18 at 18:49


















    • I don't understand can u explain this by example....or send screenshots.... if used it anywhere

      – jyoti sharma
      Nov 13 '18 at 14:42











    • please sir....when u get time ...reply me

      – jyoti sharma
      Nov 14 '18 at 10:51











    • @jyotisharma you should use Service to register your intentFilter instead of registering in your Application. Here's the Service tutorial you should take a look at: vogella.com/tutorials/AndroidServices/article.html

      – Kingfisher Phuoc
      Nov 14 '18 at 18:49

















    I don't understand can u explain this by example....or send screenshots.... if used it anywhere

    – jyoti sharma
    Nov 13 '18 at 14:42





    I don't understand can u explain this by example....or send screenshots.... if used it anywhere

    – jyoti sharma
    Nov 13 '18 at 14:42













    please sir....when u get time ...reply me

    – jyoti sharma
    Nov 14 '18 at 10:51





    please sir....when u get time ...reply me

    – jyoti sharma
    Nov 14 '18 at 10:51













    @jyotisharma you should use Service to register your intentFilter instead of registering in your Application. Here's the Service tutorial you should take a look at: vogella.com/tutorials/AndroidServices/article.html

    – Kingfisher Phuoc
    Nov 14 '18 at 18:49






    @jyotisharma you should use Service to register your intentFilter instead of registering in your Application. Here's the Service tutorial you should take a look at: vogella.com/tutorials/AndroidServices/article.html

    – Kingfisher Phuoc
    Nov 14 '18 at 18:49












    0














    You have to add alarm permission in your manifest



    <uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission>


    And also To register your broadcast



     <receiver
    android:name=".broadcast.ServiceBroadcast"
    android:enabled="true"
    android:exported="true"
    android:label="RestartServices">
    <intent-filter>
    <action android:name="restart_services"/>
    <action android:name="android.intent.action.BOOT_COMPLETED"/>
    <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
    </receiver>





    share|improve this answer



























      0














      You have to add alarm permission in your manifest



      <uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission>


      And also To register your broadcast



       <receiver
      android:name=".broadcast.ServiceBroadcast"
      android:enabled="true"
      android:exported="true"
      android:label="RestartServices">
      <intent-filter>
      <action android:name="restart_services"/>
      <action android:name="android.intent.action.BOOT_COMPLETED"/>
      <category android:name="android.intent.category.DEFAULT" />
      </intent-filter>
      </receiver>





      share|improve this answer

























        0












        0








        0







        You have to add alarm permission in your manifest



        <uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission>


        And also To register your broadcast



         <receiver
        android:name=".broadcast.ServiceBroadcast"
        android:enabled="true"
        android:exported="true"
        android:label="RestartServices">
        <intent-filter>
        <action android:name="restart_services"/>
        <action android:name="android.intent.action.BOOT_COMPLETED"/>
        <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
        </receiver>





        share|improve this answer













        You have to add alarm permission in your manifest



        <uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission>


        And also To register your broadcast



         <receiver
        android:name=".broadcast.ServiceBroadcast"
        android:enabled="true"
        android:exported="true"
        android:label="RestartServices">
        <intent-filter>
        <action android:name="restart_services"/>
        <action android:name="android.intent.action.BOOT_COMPLETED"/>
        <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
        </receiver>






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 14 '18 at 11:05









        Alesandro GiordanoAlesandro Giordano

        308110




        308110



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53263566%2fbroadcast-receiver-is-not-working-when-application-is-removed-from-background%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Use pre created SQLite database for Android project in kotlin

            Darth Vader #20

            Ondo