0

Background

I designed a rest api that acts as a interface between my android app and mysql database.As a user logs in to the app,an api key is returned from the database by the api in form of json object(along with other details).Volley parses the json object and retrieves the api key.All the further calls to the api are made after the api key is authenticated in request header.

Problem

I want to know the best way to store the parsed api key to a variable which can be used by all the activities globally to send requests to api through volley.

2 Answers2

1
  1. SharedPreferences could be the place to store it, than you can retrieve it whenever needed.

  2. Or you can call your API every time app starts, in Application class onCreate() for example, and store it there as member variable

Ilja S.
  • 1,091
  • 2
  • 12
  • 21
0

This is a pretty big 'best practice' question, and so you're going to get a lot of different answers. I like to use ProGuard as mentioned in this SO question. If you're not interested in dealing with all that at the moment though, SharedPreferences are a good place to start.

Community
  • 1
  • 1
Csteele5
  • 1,182
  • 15
  • 36