Broadcast receiver not working when app is closed

前端 未结 4 1089
遇见更好的自我
遇见更好的自我 2021-01-06 05:21

So I have two different apps made, one sends a broadcast and another receives it and displays a toast. However, when I close the receiver app the broadcast is no longer rece

4条回答
  •  逝去的感伤
    2021-01-06 05:49

    Try this way..

    Intent i = new Intent();
    i.setAction("com.example.ali.rrr");
    i.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
    i.setComponent(  
            new ComponentName("PackageNameApp2","PackageNameApp2.MainActivity"));  
    sendBroadcast(i);
    

提交回复
热议问题