0

My Requirement is login user information need to pass Main Activity.Main Activity is Tab Group Activity

Tab Group Activity I have done like this : Android Tab view

I have implemented SharedPreferences.

Login Activity part ...

   if((selectedxecutive.toString().equals("MARADANA R1")) && (password.getText().toString().equals("xont"))){
         RDExecutive rdExecutive = new CommonFunctionActivity().getExecutiveObject(selectedxecutive);
         strBusinessUnit = rdExecutive.getBusinessUnit();
         strExecutive   = rdExecutive.getExecutiveCode();
         strTerritoryCode   = rdExecutive.getTerritoryCode();


         SharedPreferences.Editor prefsEditor = myPrefs.edit();
         prefsEditor.putString("BusinessUnit", strBusinessUnit);
         prefsEditor.putString("Executive", strExecutive);
         prefsEditor.putString("TerritoryCode", strTerritoryCode);
         prefsEditor.commit();

         Intent showContent = new Intent(getApplicationContext(),MainActivity.class);
         startActivity(showContent);
   }

Retrieve in SalesRouteActivity Activity which is contain tab ... (MainActivity contain tab host details & SalesRouteActivity is first tab host)

   SharedPreferences myPrefs = this.getSharedPreferences("myLogedPrefs", MODE_WORLD_READABLE);
         String strBusinessUnits = myPrefs.getString("BusinessUnit", "");
         String strExecutives = myPrefs.getString("Executive", "");
         String strTerritoryCodes = myPrefs.getString("TerritoryCode", "");

This is give NUllPointException....

Please help me on how to store the login user values...

Thanks in advance

Community
  • 1
  • 1
Piraba
  • 6,974
  • 17
  • 85
  • 135

1 Answers1

0

Where do you initialize "myPrefs" ?

myPrefs should be the same as 

this.getSharedPreferences("myLogedPrefs", MODE_WORLD_READABLE);

in the sense,

myPrefs  = getSharedPreferences("myLogedPrefs", MODE_WORLD_READABLE);

//Also this is now how you start an activity in a childactivity,

Intent showContent = new Intent(getparent(),MainActivity.class);
         startActivity(showContent);
Hades
  • 3,916
  • 3
  • 34
  • 74
  • Its a class variable; ` SharedPreferences myPrefs;` – Piraba Aug 10 '11 at 07:50
  • does your class start up properly when u comment the sharedpreferences out? Where is this initialized? SharedPreferences.Editor prefsEditor = myPrefs.edit(); – Hades Aug 10 '11 at 08:36