Answer the question
In order to leave comments, you need to log in
How to work with refresh token in android development?
My application can perform authentication, authorization and obtain profile information. Everything is done through a token. I need to add a situation where the token has expired. (Working with RefreshToken). I don't know how to do it right. I don't know where is the best place to check this.
I am posting part of the code. It is unlikely that it will help. But let it lie.
This is MainActivity when the application starts, it checks for Null token
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SharedPreferences sharedPref = getApplicationContext()
.getSharedPreferences("userInfo", AppCompatActivity.MODE_PRIVATE);
String token = sharedPref.getString("access_token",null);
if (token != null) {
Intent intent = new Intent(MainActivity.this, Profiile.class);
startActivity(intent);
finish();
}
}
public class NetworkService {
private static NetworkService mInstance;
private static final String BASE_URL = "https://minesrv.ey.r.appspot.com";
private Retrofit mRetrofit;
private NetworkService () {
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
SharedPreferences preferences = App.Companion.getInstance().getSharedPreferences("userInfo", AppCompatActivity.MODE_PRIVATE);
OkHttpClient client = new OkHttpClient.Builder()
.addInterceptor(logging)
.addInterceptor(new AccessTokenInterceptor(preferences))
.build();
mRetrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question