Android global variable

前端 未结 14 1369
眼角桃花
眼角桃花 2020-11-21 23:32

How can I create global variable keep remain values around the life cycle of the application regardless which activity running.

14条回答
  •  南旧
    南旧 (楼主)
    2020-11-22 00:09

    Use SharedPreferences to store and retrieve global variables.

    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
    String userid = preferences.getString("userid", null);
    

提交回复
热议问题