0

OK this question has been asked many times in the past and I went through a lot of them but I still couldn't figure out what is the right way of doing this.

In my app I have a login activity. I am making some api hits inside a thread inside a class (Lets call it ApiHitter) that implements runnable. If any of these api hit returns an error I want to logout the user (might sound weird, but for some reasons I need this functionality)

Now what i have done uptill now is that inside my non-activity class (ApiHitter) I created an init fuction to get Context like this.

public static void init(Context applicationContext) {

        appContext = applicationContext;

    }

I pass context to this class at my splash activity by calling ApiHitter.init(context). Whenever I needed a context in this class this approach worked fine. But it doesn't help me to start the login activity. I tried to call init from LoginActivity as well but that doesn't work either. This is how I try to start the activity.

Intent intent = new Intent(appContext, LoginActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
(appContext).startActivity(intent);

I also tried setFlags instead of addFlags but in vain.

I am not getting any error but can't start LoginActivity.

Since I am already setting the flag I assume that context is the culprit. Any help or guidance would be appreciated. Thanks !!

varunkr
  • 5,364
  • 11
  • 50
  • 99

0 Answers0