How to know if an activity is called using startActivityForResult or simply called by using startActivity?

前端 未结 3 1816
猫巷女王i
猫巷女王i 2020-12-06 05:54

or should i send some extra data in the Intent to know the call ?if there is no predefined method,like getIntent and do something with it ?

3条回答
  •  时光说笑
    2020-12-06 06:22

    I think that you should expose several intents for the same activity in your manifest, then test the calling intent to adapt your behaviour.

    Example for your activity intent filter in the manifest:

      
        
        
        
        
      
    

    and corresponding code in your activity onCreate:

    if (getIntent().getAction().equals(Intent.ACTION_VIEW)) {
            // do whatever you need to do here
    } else if (getIntent().getAction().equals(Intent.ACTION_PICK)){
     ...
    }
    

提交回复
热议问题