how to check which Intent started the activity?

后端 未结 3 1449
深忆病人
深忆病人 2021-02-13 02:11

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 02:44

    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");
    

提交回复
热议问题