Android - launch app from broadcast receiver

前端 未结 4 447
-上瘾入骨i
-上瘾入骨i 2021-01-12 00:08

I want the broadcast receiver to launch my app this way:

  1. If the app is not in the foreground or background, launch it as if it is launched from launcher.

4条回答
  •  醉梦人生
    2021-01-12 00:41

    Assuming you already know BroadcastReceiver, you just have to do the launching like you usually do on onReceive : Therefore it will look like this

    @Override
    public void onReceive(Context context, Intent intent) {
        Intent launch_intent = new Intent("android.intent.action.MAIN");
        launch_intent.putExtra("some_data", "value");
        tiapp.startActivity(launch_intent);
    }
    

    If it is launched before, it will just resume that Activity, if not, it will start a new

提交回复
热议问题