Close application from broadcast receiver

前端 未结 3 693
梦如初夏
梦如初夏 2021-01-14 00:05

I\'m new in android programming. I\'ve tried registering broadcast receiver in activity, but my receiver not working when apps onPause. So i found that i need to registering

3条回答
  •  不知归路
    2021-01-14 01:01

    Your broadcast receiver is in the main activity class? If so you can save a global context of your app and close it later in the broadcast receiver.

    If it is on a service or provider, just send an instance of your app to it when you start/register it. Then you call finish() from that instance.

    EDIT:

    Try this:

    In your main activity create this public method:

       public static void closeActivity(){
            finish();
       }
    

    Then in your broadcast receiver call this method like:

       MainActivity.closeActivity();
    

    Hope it helps ;)

提交回复
热议问题