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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:32:24+00:00 2026-06-08T03:32:24+00:00

Hello good morning friends, I am working for the application that required login/logout funcationality.

  • 0

Hello good morning friends,

I am working for the application that required login/logout funcationality. Here I have login success,After that logout also work perfect but when I try for again login into the application that give me 406 status code. here I am using sharedpreferences for the login/logout funcationality.

But when I restart the application it works random means it may sometimes login or sometimes not. But when close the emulator again start then works perfect.

Login.java

please check the onPostExecute() method for below code

  @Override
    protected Void doInBackground(Void... params) {
        // TODO Auto-generated method stub

            String loginURL = "http://www.cheerfoolz.com/rest/user/login";

            strResponse = util.makeWebCall(loginURL, uName, Password);

              try {
                JSONObject jsonSession = new JSONObject(strResponse);

                session = new SessionID();
                SessionID.sessionId = jsonSession.getString("sessid");
                SessionID.sessionName = jsonSession.getString("session_name");

                JSONObject jsonuser=jsonSession.getJSONObject("user");
                SessionID.userID = jsonuser.getInt("uid");


            } catch (JSONException e1) {
                e1.printStackTrace();
            }

        return null;
    }

    @Override
    public void onPostExecute(Void result) {
        // TODO Auto-generated method stub
        super.onPostExecute(result);

            try {
                if (strResponse.substring(KEY_SUCCESS) != null) {
                    txterror.setText("");

                    SharedPreferences userDetails =getSharedPreferences("userdetails", MODE_PRIVATE);
                    Editor edit = userDetails.edit();
                    edit.putString("username", uName);
                    edit.putString("password", Password);
                    edit.commit();


                } else {
                    txterror.setText("Username and Password Not valid !!!");
                }
            } catch (Exception e) {
                // TODO: handle exception
            }
    }

Main.java

In main class I have a logout button.

case R.id.home_btn_feature_logout:

        SessionID.setUserID(0);

        SharedPreferences settings = getSharedPreferences("userdetails", MODE_PRIVATE);
        SharedPreferences.Editor editor = settings.edit();
        editor.remove("username");
        editor.remove("password");
        editor.clear();
        editor.commit();

        login.setVisibility(View.VISIBLE);
        logout.setVisibility(View.GONE);

        break;

Here I think session data is not clear properly, Plese let me know where I do mistake. And there is another solution for the login/logout then inform me.

Thank you.

  • 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-08T03:32:26+00:00Added an answer on June 8, 2026 at 3:32 am

    I dont think there is anything wrong with your SharedPreferences API.I checked the Rest web service URL that you are using and its a Drupal site.You have to call user.logout to logout first.Since you are using REST try this.I havent tested this but it should work

    String loginURL = "http://www.cheerfoolz.com/rest/user/logout";
    
    strResponse = util.makeWebCall(loginURL,sessionid);
    

    Also you might want to check if you have correctly configured your REST server endpoint.Check if you have enabled application/x-www-form-urlencoded content type of your REST service endpoint.Go to Server from Edit Resources in Services.Since it is working fine when login is called the first time I doubt this might be the problem.But still check it.

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

Sidebar

Related Questions

Hello everyone I have a question that I will describe as good as I
Servlet is very good looking and reading files that have English names like hello.txt.
I have this CSV file that contain this following, 10000,hello 10000,bye 10000,good And, my
Hello good morning everyone, i have an iphone app which is still in development
Hello Everyone and Good Morning, I am working with the page: http://702wedding.com/live/ And it
Hello Good People !! I have a web application (my first of this type)
I have a string: hello good old world and i want to upper case
Hello android designers, 1-I have been wondering. Is it a good design approach to
I have this string @[123:peterwateber] hello! good day! I wanna change it to <a
I have this little text <div> Hello world<br> this is a good<br> text! <br><br>

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.