2012-03-01 9 views
0

Cookieを取得して新しいアクティビティを開始するアクティビティが1つあるとします。新しいアクティビティにクッキーを渡す方法は?

Intent myIntent = new Intent(this, act2.class); 
this.startActivity(myIntent); 

しかし、そのクッキーを新しいアクティビティに渡すにはどうすればよいですか?

ありがとうございます!

答えて

2

putExtraメソッドをIntentとすると、1つのアクティビティから別のアクティビティにデータを送信する必要があります。

例えば、

Intent myIntent = new Intent(this, act2.class); 
myIntent.putExtra("CookieKey",cookieValue); 
this.startActivity(myIntent); 

や他の活動では、あなたが

String cookie=getIntent().getStringExtra("CookieKey"); 

またはあなたが使用することができ、より明確な方法でを使用して、このエキストラを取得することができます:

Bundle bundle=getIntent().getExtras(); 

    if(bundle!=null) 
    { 
     if(bundle.contains("CookieKey")){ 

      String cookie=bundle.getString("CookieKey"); 
     } 
    } 
+0

ありがとう、cookieValueを作成するには、MyCookie.toString()を実行しますか? –

+0

また、この文字列を後でクッキーに戻すにはどうしたらいいですか? :) –

関連する問題