Dealing with implicit intent future deprecation in Lollipop

前端 未结 3 426
清歌不尽
清歌不尽 2021-02-04 10:06

To transmit data to other applications I\'ve been using implicit intents as in examples below:

Intent intent = new Intent();
intent.setAction(\"com.example.OpenU         


        
3条回答
  •  离开以前
    2021-02-04 10:55

    As said in other comments and answers, the change is only relevant to bindService and not sendBroadcast, so if that's the case (as in your sample code) - you don't need to change anything.

    If you do use bindService, the way to make an implicit Intent to an explicit Intent is to use a ComponentName and set it on the service Intent using the setComponent or setClass method.

    From the Intent class documentation:

    Intent Resolution

    There are two primary forms of intents you will use.

    Explicit Intents have specified a component (via setComponent(ComponentName) or setClass(Context, Class)), which provides the exact class to be run. Often these will not include any other information, simply being a way for an application to launch various internal activities it has as the user interacts with the application. Implicit Intents have not specified a component; instead, they must include enough information for the system to determine which of the available components is best to run for that intent.

提交回复
热议问题