Groups
Groups
Sign in
Groups
Groups
Android-SDK-Japan
Conversations
About
Send feedback
Help
Activity間の数値の渡し方
469 views
Skip to first unread message
とい
unread,
Oct 20, 2009, 9:54:10 PM
10/20/09
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Android-SDK-Japan
Activity間の文字列の渡し方は参考書などに書かれているのですが、
数値の渡し方が分かりません。
このように、数値を渡そうとしてみるのですがうまくいかず・・・
putExtraでは数値は渡せないのか、putExtra自体を勘違いしてるのか・・・
どうかご伝授お願いします。
-----------------------------Test.java------------------------------
int number = 1;
Intent intent = new Intent(Test.this,Test2.class);
intent.putExtra("NUMBER_1",number);
----------------------------Test2.java------------------------------
Bundle extras = getIntent().getExtras();
if (extras != null){
int number1 = extras.getInt("NUMBER_1");}
asachie
unread,
Oct 20, 2009, 10:34:04 PM
10/20/09
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Android-SDK-Japan
最後の行で、キーを指定する際にパッケージ名が必要だったと思います。
> int number1 = extras.getInt("NUMBER_1");}
int number1 = extras.getInt("org.example.test.NUMBER_1");}
とい
unread,
Oct 20, 2009, 11:35:58 PM
10/20/09
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Android-SDK-Japan
星さんからいただいたアドバイスで解決しました!
内容は、get側を以下にするということでした。
num = getIntent().getIntExtra("NUMBER_1”, 0 );
getIntExtraの引数の0はインテントから取得できなかったときに変わりに入る値。
星さん、asachieさん、みなさんありがとうございました!
Reply all
Reply to author
Forward
0 new messages