J
J
Jores_T2019-03-05 22:26:32
Java
Jores_T, 2019-03-05 22:26:32

How to pass Context to OkHttp3?

Hello, I am a complete newbie to java.
There is an example of using PersistentCookieJar on github:

ClearableCookieJar cookieJar =
                new PersistentCookieJar(new SetCookieCache(), new SharedPrefsCookiePersistor(context));

I read several articles about context and what it is. Roughly understood, but absolutely do not understand how to use it in this case. What exactly to transmit?
Tried like this:
import android.content.Context;
Then further in the class I declared:
private Context context;
Also tried:
private Context context = getApplicationContext();
None of this works - the app just crashes.
Can you please tell me how to declare this context correctly and how to use it in this case?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question