如何将值从正常活动传递到选项卡组活动

时间:2011-08-10 07:39:59

标签: android

我的要求是登录用户信息需要传递Main Activity.Main Activity是Tab Group Activity

标签组活动我这样做了: Android Tab view

我已经实施了SharedPreferences。

登录活动部分......

   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);
   }

检索SalesRouteActivity活动,其中包含选项卡...(MainActivity包含选项卡主机详细信息& SalesRouteActivity是第一个选项卡主机)

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

这是给NUllPointException ....

请帮助我了解如何存储登录用户值...

提前致谢

1 个答案:

答案 0 :(得分:0)

你在哪里初始化“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);