how to check which Intent started the activity?

后端 未结 3 615
暖寄归人
暖寄归人 2021-02-13 02:08

I have many activities. Each one of them has an intent which refers to the same activity. Is there a way to find out which intent started the activity?

3条回答
  •  南笙
    南笙 (楼主)
    2021-02-13 03:04

    You didn't provide any context, so here's one general approach.

    Put an extra into each Intent type, like a unique int or String:

    intent.putExtra("Source", "from BroadcastReceiver");
    

    and use:

    String source = getIntent().getStringExtra("Source");
    

提交回复
热议问题