Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6032397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:19:41+00:00 2026-05-23T05:19:41+00:00

I am wondering what is the best way to do this: I do queries

  • 0

I am wondering what is the best way to do this:

I do queries to an API which needs the user to be logged. When the application starts doing the login, if it is correct will store user/pass in preferences.

Once we are logged, if an error of NOT_LOGGED occurrs in any activity when I am trying to call the method from the API, I will retrieve user/pass from preferences and do the login again.
If it’s succesfull my program will try again the API query. If not, it will be open the LoginActivity. That’s where I wonder what is best to do.

As the method to “Relogin” it’s use from several activities I have decided to implemented in MyApp, a class which extends from Application and keep objects alive all the activitiy’s lifecycle. But I cant close the stack of activities from there, can I?
My idea is to close the current stack of activities and open the Login one, using this:

if(!mMyApp.relogin(mCtx)){
    Intent intent=new Intent(mCtx,ActivityLogin.class);    
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);                    
    startActivity(intent);
    finish();
}

But I have to call the method finish from the proper activity but not from MyApp.
So I have to repeat all the code in every single class I use the relogin(mCtx) method.

Do you think I taclking the problem in the right way, or should I change the strategy? And BTW, what do you think is the best place to implement methods that will be called from different activities. I have been using singletons so far, but if the gc clean memory I might lose that information.

Thanks,
David.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T05:19:41+00:00Added an answer on May 23, 2026 at 5:19 am

    If you make relogin take in the Activity instance (instead of a generic Context) you can invoke the finish method in there. Try it out and see: it should work.

    And in anycase when you use Intent.FLAG_ACTIVITY_CLEAR_TOP it will automatically destroy all Activities, so the finish is probably redundant.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Wondering what the best / good way of doing this would be in jQuery.
I've been wondering what the best way to do this would be. I've got
I've been wondering what's the best way to do this with a language like
I am wondering if this is the best way to go about solving my
I'm just wondering if this is possible, and if not, the best way to
I'm wondering the best way to approach this. I have a JavaScript file in
I was wondering about the best way to do this: I have an app
I am wondering the best way to solve this problem. I have a datatable
HI everyone, I was just wondering what the best way to make multiple queries
I was wondering the best way to approach this. I am using Userena as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.