keeping a variable value across all android activities

前端 未结 5 1128
醉话见心
醉话见心 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:42

    You can use the ApplicationContext too. In your Manifest, you should have something like this :

    
    

    Now, you can access to the Application from any Activity thanks to :

    MyApp application = (MyApp)this.getApplicationContext();
    

    You can put your attributes in this class, it'll be accessible anywhere in your app. MyApp must extends Application. See Manifest and Application

提交回复
热议问题