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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:26:47+00:00 2026-06-09T03:26:47+00:00

I have 2 activities 1.Register.java 2.SecureXActivity.java In Register activity i am doing registration of

  • 0

I have 2 activities
1.Register.java
2.SecureXActivity.java
In Register activity i am doing registration of my application using shared preferences. I have used shared preferences to show Register activity only once. Now my requirement is take
user name from register activity which will be shown only once at the time of registration and save it in SecureXActivity activity, after the registration only this activity will be visible to user. So please help me in this regard? I am new to android.

My code is given below

Register.java

public class Register extends Activity
{
public static final String PREFS_NAME = "LoginPrefs";
public static final String USER_NAME = "USER";

@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.register);

    /*
     * Check if we successfully logged in before.
     * If we did, redirect to home page
     */
    SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
    if (settings.getString("logged", "").toString().equals("logged")) 
    {
        Intent intent = new Intent(Register.this, SecureXActivity.class);
        startActivity(intent);
    }

    Button b = (Button) findViewById(R.id.btnRegister);
    b.setOnClickListener(new OnClickListener() 
    {
        public void onClick(View v) {
            EditText username = (EditText) findViewById(R.id.reg_employeeid);
            EditText password = (EditText) findViewById(R.id.reg_password);
            String welcm ="Welcome";
            String space = " ";
            EditText firstname = (EditText)findViewById(R.id.reg_firstname);
            EditText lastname = (EditText)findViewById(R.id.reg_lastname);
            String getfirstname = firstname.getText().toString();
            String getlasttname = lastname.getText().toString();
            String welcome=welcm.concat(space).concat(getfirstname).concat(space).concat(getlasttname);





            if(username.getText().toString().length() > 0 && password.getText().toString().length() > 0 ) 
            {
                if(username.getText().toString().equals("test") && password.getText().toString().equals("test")) 
                {
                    SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
                    SharedPreferences.Editor editor = settings.edit();
                    editor.putString("logged", "logged");
                    editor.commit();    
                    Intent intent = new Intent(Register.this, SecureXActivity.class);
                    intent.putExtra("name", welcome);
                    startActivity(intent);
                }
            }
        }
    });
}
} 

SecureXActivity.java

public void onCreate(Bundle savedInstanceState)
{
    Thread.setDefaultUncaughtExceptionHandler(new exceptionHandler(this));
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
        Bundle extras =getIntent().getExtras();

    if (extras != null)
    {
        String value = extras.getString("name");
        TextView txtwelcm= (TextView)findViewById(R.id.textViewwelcm);
        txtwelcm.setText(value);
    }
}

I want a value from one activity to another activity and value should be saved to another activity. In my above code i have done this using intent. But the problem is value is shown only once in second activity. Value is not visible when i press back button or home key?How to do this.

Added in response to @Picarus:

The problem is i am using same shared preferences to show the register activity only once.
But it not showing the name on SecureX activity.Is it possible to use same shared preference to carry value from register activity to securex activity

The Entire code is Given below once again
Register.java

    public class Register extends Activity 
    { 
public static final String PREFS_NAME = "LoginPrefs"; 


@Override 
public void onCreate(Bundle savedInstanceState)  
{ 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.register); 

    /* 
     * Check if we successfully logged in before. 
     * If we did, redirect to home page 
     */ 
    SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); 
    if (settings.getString("logged", "").toString().equals("logged"))  
    { 
        Intent intent = new Intent(Register.this, SecureXActivity.class); 
        startActivity(intent); 
    } 

    Button b = (Button) findViewById(R.id.btnRegister); 
    b.setOnClickListener(new OnClickListener()  
    { 
        public void onClick(View v) { 
            EditText username = (EditText) findViewById(R.id.reg_employeeid); 
            EditText password = (EditText) findViewById(R.id.reg_password); 
            String welcm ="Welcome"; 
            String space = " "; 
            EditText firstname = (EditText)findViewById(R.id.reg_firstname); 
            EditText lastname = (EditText)findViewById(R.id.reg_lastname); 
            String getfirstname = firstname.getText().toString(); 
            String getlasttname = lastname.getText().toString(); 
            String welcome=welcm.concat(space).concat(getfirstname).concat(space).concat(getlasttname); 





            if(username.getText().toString().length() > 0 && password.getText().toString().length() > 0 )  
            { 
                if(username.getText().toString().equals("test") && password.getText().toString().equals("test"))  
                { 
                    SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); 
                    SharedPreferences.Editor editor = settings.edit(); 
                    editor.putString("name", welcome); 
                    editor.commit();     
                    Intent intent = new Intent(Register.this, SecureXActivity.class); 
                    //intent.putExtra("name", welcome); 
                    startActivity(intent); 
                } 
            } 
        } 
    }); 
} 
} 

SecureXActivity.java

public class SecureXActivity extends Activity 
{ 
public static final String PREFS_NAME = "LoginPrefs"; 

private ListView m_listview; 
Button btnSendlogs; 
Button btnMailadmin; 
Button btnContactSupport; 
Button btnSettings; 

@Override 
public void onCreate(Bundle savedInstanceState) 
{ 
    Thread.setDefaultUncaughtExceptionHandler(new exceptionHandler(this)); 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    //Here we are setting the installation date of a application 
    ContextWrapper context = this; 
    PackageManager packageManager = context.getPackageManager(); 
    ApplicationInfo appInfo; 
    try 
    { 
        appInfo = packageManager.getApplicationInfo("com.simsys.securex", 0); 
        String sourceDir= appInfo.sourceDir; 
        long dateTimeSync= new File(sourceDir).lastModified(); 
        String DateTimeStamp=getDate(dateTimeSync, "dd/MM/yyyy hh:mm:ss"); 
        String dateTimeSync2="Installed_Date:"; 
        String dateTimeSync3=dateTimeSync2.concat(DateTimeStamp); 
        TextView txtCurrentTime= (TextView)findViewById(R.id.textViewdatetime); 
        txtCurrentTime.setText(dateTimeSync3); 
    }  
    catch (NameNotFoundException e)  
    { 
        e.printStackTrace(); 
    } 
    //Here We Welcome the user 

    //List View 
    m_listview = (ListView) findViewById(R.id.list_view); 
    ArrayList<String> listItems=new ArrayList<String>(); 
    listItems.add("CAMERA"); 
    listItems.add("RECORDER"); 
    ArrayAdapter<String> adapter = 
            new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, listItems); 

    m_listview.setAdapter(adapter); 
    if(isBluetoothServiceRunning()) 
    { 
        listItems.add("BLUETOOTH"); 
    } 
    if(isGprsServiceRunning()) 
    { 
        listItems.add("GPRS"); 
    } 
    if(isWifiServiceRunning()) 
    { 
        listItems.add("WIFI"); 
    } 
    adapter.notifyDataSetChanged(); 
    //Call to Buttons Functionality 
    btnSendlogs = (Button) findViewById(R.id.button_sendlogs); 
    btnSendlogs.setOnClickListener(myhandler1); 
    btnMailadmin=(Button) findViewById(R.id.button_mailtoadmin); 
    btnMailadmin.setOnClickListener(MailadminHandler); 
    btnContactSupport = (Button) findViewById(R.id.button_contactsupport); 
    btnContactSupport.setOnClickListener(ContactSupportHandler); 

} 

//Navigation from Registration to Main page 
public boolean onCreateOptionsMenu(Menu menu)  
{ 
    MenuInflater Inflater = getMenuInflater(); 
    Inflater.inflate(R.menu.menu, menu); 
    return true; 
} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) 
{ 
    if (item.getItemId() == R.id.logout) 
    { 
        SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); 

        String data2=settings.getString("name", ""); 
        TextView txtwelcm= (TextView)findViewById(R.id.textViewwelcm); 
        txtwelcm.setText(data2); 
        SharedPreferences.Editor editor = settings.edit(); 
        editor.remove("name"); 
        editor.commit(); 
        finish(); 
    } 
    return super.onOptionsItemSelected(item); 
} 
  • 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-09T03:26:48+00:00Added an answer on June 9, 2026 at 3:26 am

    For implementing sharedPreferences use following code

     Sharedpreferences myPref = this.getSharedPreferneces("your_file_name",MODE);
     SharedPreferences.Editor editor = myPref.edit();
     editor.putString("String_Name",value);
     editor.putInt("Int_Name","value");
    

    To retrieve from SharedPreferences

       Sharedpreferences myPref = this.getSharedPreferneces("your_file_name",MODE);  
       String stringValue = myPref.getStirng("String_Name","DEFAULT_VALUE");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have four activities namely, Demo_tabActivity.java [main activity] Tabhost.java The below two activities are
I have four activities namely, Demo_tabActivity.java [main activity] Tabhost.java The below two activities are
Im making a multi activity application and the first two activities i made have
I have two Activities along with one Application class, and whenever I call my
i have to activities AnswerQuestion.java and SendAnswerToServer.java , and i want to send data
I have two activities. In first I come to the second activity from first
I have 2 activities. The first activity is an activity that parses JSON data
I have an Android application with a main activity that is the tabhost. I'm
I have three activities in my application ... I use an intent to navigate
I have two activities; Home is my first activity and Settings is my second

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.