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

  • Home
  • SEARCH
  • 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 6342805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:18:48+00:00 2026-05-24T20:18:48+00:00

My appliaction features a menu with a logout button that allows you to log

  • 0

My appliaction features a menu with a logout button that allows you to log out from any Activity. This has been working fine. It used to log out to the app’s Welcome screen, but I recently changed it to log out to the device’s home screen. Now, when I log out and open the app, it force closes. On the second attempt to start the app, it will start correctly.

On the first attempt, it seems to try to load the Activity that was running when the user logged out, despite LogCat showing it starting the correct Intent:

08-13 17:14:18.983: INFO/ActivityManager(59): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=uk.ac.ic.doc.vmw10.wherewolf/.activities.Welcome }
08-13 17:14:19.053: VERBOSE/WWA(8611): setting up
08-13 17:14:19.064: DEBUG/AndroidRuntime(8611): Shutting down VM
08-13 17:14:19.064: WARN/dalvikvm(8611): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
08-13 17:14:19.083: ERROR/AndroidRuntime(8611): FATAL EXCEPTION: main
08-13 17:14:19.083: ERROR/AndroidRuntime(8611): java.lang.RuntimeException: Unable to resume activity {uk.ac.ic.doc.vmw10.wherewolf/uk.ac.ic.doc.vmw10.wherewolf.activities.Tabs}: java.lang.NullPointerException

Immediately after it starts the correct Intent, a verbose message is output from the wrong activity, and then the app crashes due to a NullPointerException. Why is it not starting the Welcome activity, as the Intent claims it is?

Here’s the logout function:

public void logout() {
    SharedPreferences.Editor prefEditor = preferences.edit();
    prefEditor.remove(PASSWORD);
    prefEditor.remove(FIRST_NAME);
    prefEditor.remove(LAST_NAME);
    prefEditor.remove(EMAIL_ADDRESS);
    prefEditor.remove(DATE);    
    prefEditor.remove(PICTURE); 
    prefEditor.remove(TOKEN);   
    prefEditor.commit();

    final Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_HOME);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    syncTask.cancel(true);
    dbHelper.close();
    dbHelper=null;
    firstRun = true;
    startActivity(intent); 
}

Edit: Here’s the onCreate method for the Welcome Activity:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    Log.v(TAG, "preferences: "+preferences.getAll());
    if(preferences.contains(WhereWolfActivity.EMAIL_ADDRESS)) {
        Log.v(TAG, "user preferences saved from previous session: "+preferences.getAll().toString());
        intent = new Intent(getApplicationContext(), Tabs.class);
        startActivity(intent);
        finish();
    }
    else if(preferences.contains(WhereWolfActivity.USER_ID) &! preferences.contains(WhereWolfActivity.EMAIL_ADDRESS)) {
        Log.v(TAG, "known user returning to log in");
        intent = new Intent(getApplicationContext(), Login.class);
        startActivity(intent);
        finish();
    }
    else {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.welcome);
    }  
}

Edit:

Not only is it starting the wrong Activity, it is not calling the onCreate method of that Activity, but it does call onStart. Ths suggests that it is trying to pick up where it left off, even though that’s not what I want it to do! How can I persuade it not to do this?

Edit:

As all my ‘logged in’ Activity’s have a superclass they inherit from, I added a bit to that superclass’s onStart() method that would check if the user was logged in, and if not it would start the Welcome Activity:

public void onStart () {
    super.onStart();
    if(!preferences.contains(EMAIL_ADDRESS)) {
        Log.v(TAG, "not logged in");
        Intent intent = new Intent(getApplicationContext(), Welcome.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);
        finish();
    }

This hasn’t worked. Here’s the LogCat output:

08-13 20:41:10.223: INFO/ActivityManager(59): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=uk.ac.ic.doc.vmw10.wherewolf/.activities.Welcome }
08-13 20:41:10.254: VERBOSE/WWA(2171): not logged in
08-13 20:41:10.263: INFO/ActivityManager(59): Starting activity: Intent { flg=0x4000000 cmp=uk.ac.ic.doc.vmw10.wherewolf/.activities.Welcome }
08-13 20:41:10.273: VERBOSE/WWA(2171): setting up
08-13 20:41:10.320: DEBUG/AndroidRuntime(2171): Shutting down VM
08-13 20:41:10.320: WARN/dalvikvm(2171): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
08-13 20:41:10.343: ERROR/AndroidRuntime(2171): FATAL EXCEPTION: main
08-13 20:41:10.343: ERROR/AndroidRuntime(2171): java.lang.RuntimeException: Unable to resume activity {uk.ac.ic.doc.vmw10.wherewolf/uk.ac.ic.doc.vmw10.wherewolf.activities.Tabs}: java.lang.NullPointerException

The superclass has the tag WWA. As you can see, it says ‘not logged in’, then starts the Welcome Activity, and then carries on anyway. Any ideas?

  • 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-24T20:18:50+00:00Added an answer on May 24, 2026 at 8:18 pm

    I solved the problem by adding this to the onPause() method of my superclass:

    if(!preferences.contains(EMAIL_ADDRESS)) { // this means the user has logged out
        finish();
    }
    

    Now, when the user logs out, all Activity’s are finished properly. I also changed it back to logging out to the log in screen rather than logging out to the device’s home screen after reading this post: Is quitting an application frowned upon?

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

Sidebar

Related Questions

I am building an application which has requirements stating that all browser features must
I have been trying to figure out how to use the Routing features with
I have a pure Winapi application that needs a few new features. One of
What are the C# 3.0 language features we can use in an application that
Microsoft Visual C++ 2008 Feature Pack has ribbon menu support. Is it possible to
I have a custom feature, and I'd like to link to that functionality from
I want to add a custom right-click menu to my web application. Can this
Our application launches ListActivity that displays two menu options with launch a football game
This samplet is from a project I am working on. My client uses software
I am creating a Facebook iFrame tab application that features weekly interviews and uses

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.