Get the Application Context In Fragment In Android?

后端 未结 8 1484
無奈伤痛
無奈伤痛 2020-12-02 08:36

I have stored some data to a Global Class By using the Application Context In One Activity. Later I have to Retrieve those values in A Fragment. I have done something like t

8条回答
  •  萌比男神i
    2020-12-02 09:37

    you can define a global variable :

    private Context globalContext = null;
    

    and in the onCreate method, initialize it :

    globalContext = this.getActivity();
    

    And by that you can use the "globalContext" variable in all your fragment functions/methods.

    Good luck.

提交回复
热议问题