2012-05-06 7 views
0

私はフィットネスアプリを実装しています。このアプリのタブレイアウトがあり、最初のタブには位置(緯度、経度)、速度、その他のステータスが表示され、2番目のタブには実行中のルートが地図のポリラインとして表示されるGoogleマップが表示されます。タブレイアウトで2つのアクティビティ間でデータを転送

最初のタブアクティビティには、新しい場所を受け取るロケーションマネージャがあります。

私の質問は、最初のタブのアクティビティから受信したデータをGoogleマップのタブアクティビティに転送するにはどうすればいいですか?

私が知っているように、intent.putExtra()とstartActivity()を使用すると、2つのアクティビティ間でデータを転送できますが、startActivity()を呼び出すとすぐにマップのアクティビティに移動します。しかし、マップ内のポリラインを更新してステータスタブに残したいと思います。

ヒント事前に

感謝:)ソースActivityから必要な値への即時アクセスを持っているあなたの目的地アクティビティで

答えて

1

私はそのコードでこれを解決し[OK]を:私は、ユーザー名とパスワードの文字列を渡す必要があり、私のログイン・アクティビティー(第一の活動)における

:私は、TABハンドラクラスにこの文字列を送信

btnLogin.setOnClickListener(new OnClickListener(){ 
     public void onClick(View v) {    
      String userName = txtUsername.getText().toString(); 
      String password = txtPass.getText().toString(); 
      //instance for UserFunctions. 
      UserFunctions userFunction = new UserFunctions(); 
      JSONObject json = userFunction.loginUser(userName, password); 
      //Check login response 
      try { 
       if(json.getString(KEY_REQUESTRESULT)!= null){ 
        txtErrorM.setText(""); 
        //Log.e("Passed fine:", "first if condition"); 
        String res = json.getString(KEY_REQUESTRESULT);//Obtaining the value 0 or 1 from the KEY loginstatus from JSONObject. 
       if(Integer.parseInt(res) == 1){ 
        Intent iii = new Intent("com.mariposatraining.courses.MariposaTrainingActivity"); 
        Bundle bundle1 = new Bundle(); 
        Bundle bundle2 = new Bundle(); 
        bundle1.putString("UN", userName); 
        bundle2.putString("PW", password); 
        iii.putExtras(bundle1); 
        iii.putExtras(bundle2); 

        //iii.putExtra("userName", userName); 
        //iii.putExtra("Password", password);      
        startActivity(iii); 
        finish(); 
        //Log.e("OBJECTOO", json.toString()); 
       } 

とその後、この情報を管理アクティビティ:

:クラスで

public class MariposaTrainingActivity extends TabActivity { 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    requestWindowFeature(Window.FEATURE_NO_TITLE); 
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
    WindowManager.LayoutParams.FLAG_FULLSCREEN); 
    setContentView(R.layout.main); 

    TabHost tabHost = getTabHost(); 
    TabHost.TabSpec spec ; //recurse to the property tabs 
    Intent intent; //intent for open tabs 

    //created intent for open the class tab1 

    intent = new Intent().setClass(this, ListViewerIncompleted.class); //List 2 Incompleted 
    spec = tabHost.newTabSpec("ListViewerIncompleted").setIndicator("INCOMPLETED").setContent(intent); 
    tabHost.addTab(spec); 
    Bundle bundle1 = getIntent().getExtras(); 
    String userName=bundle1.getString("UN"); 
    Bundle bundle2 = getIntent().getExtras(); 
    String password=bundle2.getString("PW"); 
    Bundle bundle3 = new Bundle(); 
    Bundle bundle4 = new Bundle(); 
    bundle3.putString("UN", userName); 
    bundle4.putString("PW", password); 
    intent.putExtras(bundle3); 
    intent.putExtras(bundle4);}} 

は、この情報を使用しますこれはあなたのアイデアを与える

Bundle bundle3 = getIntent().getExtras(); 
    String userName=bundle3.getString("UN"); //Getting the userName 
    Bundle bundle4 = getIntent().getExtras(); 
    String password=bundle4.getString("PW"); 

希望...

2

はワンGlobal classdeclare static varibleを作成し、それに値を割り当て、別のクラスを使用します。 その他の方法

Intent i =new Intent()setClass(this, ListViewerIncompleted.class); 
i.putStringArrayListExtra(name, value); 
関連する問題