keeping a variable value across all android activities

前端 未结 5 1126
醉话见心
醉话见心 2020-12-06 12:25

I have a database with one row of data that will be used across a number of activities. I need to be able to keep the row id available in all activites so I can read and wri

5条回答
  •  时光取名叫无心
    2020-12-06 12:59

    Another way is to create a application class which is available for all activities. To do that, you have to extend you Manifest with

     
    

    and create a new Class

    public class MyApplication extends Application {
    public int rowId = 0;
    }
    

    inside the activities, you can access the rowId by

    int mRowId = ((MyApplication) getApplicationContext()).rowId;
    

提交回复
热议问题