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 8247025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:42:17+00:00 2026-06-07T22:42:17+00:00

Say I have 4 Activities: Login , Sync , Main , Details . Main

  • 0

Say I have 4 Activities: Login, Sync, Main, Details.

Main and Details can only be accessed if the user is logged in and passed the synchronization phase. Main can be accessed from an icon on the drawer. Details can be accessed from Main and from the notifications.

The user is logged off after 30 minutes of inactivity (with a timer on a Service).

I am not sure which way I should take to make sure the user is logged in. Here are my two scenarios:

  • The icon launches Login which checks if the user is logged in, then launches Synch, which does the same and launches Main.
  • The icon launchs Main which checks is the user is logged in, if not, launch Login. Login closes itself to show Main that was on the back stack.

And then there is also Details that needs to checks if the user is logged in.

The second scenario seems more correct to me, because it allows to launch other Activities than Main, but it will force me to duplicate the check code in every Activity that needs to have the user logged in. (I have more than 2 activities).

Why way should I take? Why?

  • 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-06-07T22:42:18+00:00Added an answer on June 7, 2026 at 10:42 pm

    You can extend a BaseActivity which implements all your checking code, then any new Activity you use will have it built in.

    I use this in an app which has access to 50% of the Activities without logging in and displays a prompt using startActivityForResult(...) to catch the success or failure of the login attempt.

    It works really well and keeps everything neatly encapsulated 🙂

    EDIT

    Here is a code snippet to modify as you wish:

    /**
     * This is an abstract class that all Activities will be based on.
     */
    public abstract class BaseActivity extends ActionBarActivity
    {
        protected static final int    SHOW_WALLET       = 100;
        protected static final int    SHOW_OFFER_DETAIL = 101;
        protected static final int    REGISTER          = 102;
        protected static final int    SHOW_ACCOUNT      = 103;
    
        protected static final int    LOGGED_IN_OK      = 103;
        protected static final int    REGISTERED_OK     = 104;
    
        protected static final int    DIALOG_DELAY      = 300;
        // for passing data in extras
        protected static final String TEXT_SEARCH       = "text_search";
        protected static final String SEARCH_TERM       = "search_term";
    
        protected boolean             mAlternateTitle   = false;
        private Dialog                loading;
        private Runnable              showDialog;   
    
             protected final void openAccount()
            {
                Intent i;
                if ( LoginManager.getInstance().isLoggedIn() )
                {
                    i = new Intent( this, MyAccountActivity.class );
                    startActivity( i );
                }
                else
                {
                    i = new Intent( this, LoginActivity.class );
                    startActivityForResult( i, SHOW_ACCOUNT );
                }
            }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an app that contains several activities...so lets say user is navigating activity
Is the TransactionScope can be used only for Database/ADO.NET related methods? Say, I have
Let's say I have 4 activities in my app: A (main activity) B C
I have 2 activities - Say Activity A and B. My main activity(A) has
Lets say you have one main activity called main, and other sub-activities that do
I have two activities, say LoginActivity which contains a login UI and HomeActivity .
Say we have two activities, Activity1 and Activity2. In Activity1's onClick() method, we have
Problem : I have say 4 activities A, B, C and D. A --
Requirement I have an application with 2 activities, say A and B , with
Say I have 2 activities (ActivityOne and ActivityTwo). How would I call ActivityTwo from

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.