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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:07:12+00:00 2026-06-07T08:07:12+00:00

I want to pass strings to all pages in my android app. When the

  • 0

I want to pass strings to all pages in my android app. When the user logs in I save userName and others to strings. I want to send the strings over multiple pages. How can I do that?

I have tried to send it through Intent

Intent myIntent = new Intent(view.getContext(), Help.class);  
myIntent.putExtra("userName", userNameString);
startActivityForResult(myIntent, 0); 

But when I go to another page I dont want to keep sending the data through Intent every time.

I have tried to get it from the class where I parse and put them in strings

HomeScreen home = new HomeScreen();
String userName= home.userNameString;

But since i am creating a new instance of the HomeScreen then userNameString is null

Any help will be greatly appreciated

  • 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-07T08:07:14+00:00Added an answer on June 7, 2026 at 8:07 am

    Beware of using a static or instance variable to hold this state as the memory state of an Android application can be in flux. Data only stored in memory can be destroyed without your knowledge if your application process is killed while in the background.

    The simplest mechanism would be to persist your data into SharedPreferences that you can access from any place in the application. So, first you save the string that you get from login (this is called inside an Activity, FYI):

    //Write the username string to preferences
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    prefs.edit().putString("userName", userNameString).commit();
    

    Then elsewhere in your application (i.e. other Activity instances) can read that string:

    //Read the username string
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    String userName = prefs.getString("userName", "");
    

    With SharedPreferences, your values are actually persisted, meaning they will live forever on disk and won’t go away just because your application’s memory is reset (this is usually an advantage, especially for login information). Because of this, you will also need to remove the string when your user “logs out” like so:

    //Remove the username string from preferences
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    prefs.edit().remove("userName").commit();
    

    There are also methods like contains() to allow you to check if the value is currently saved (is the user logged in?), etc.

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

Sidebar

Related Questions

I have one application in which I want to pass data between Pages (Views)
i have a user control in which i want to pass page url to
I have a Silverlight Windows Phone 7 app with two pages. I want to
I want to pass string as a parameter in with my jni. but when
I want to pass a string that contains few words to jQuery when click
i want to pass a string from an input box that after submition automatically
I have the following scenario where I want to pass in string and a
I want to pass '#' to the query string like ?page.aspx?someParam=1234#5 .
I want to pass sValue that contain non-English String .... $.post(ajax.php?module=test&action=updates&id=+id+&field=+field+&val=+sValue; ... Then $valUpdate
I want to pass an object (not just a string or integer) from a

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.