創建一個button,在intent中添加:
intent.putExtra("test","test");
在onReceive中有點小毛病:
Bundle extras = intent.getExtras();
Log.v("Test", "Ok lets see");
String t=extras.getString("test");
Log.v("Test", "t="+t);
if(t=="test") t="tada";
else t="test";
Log.v("Test", "Ok...t="+t);
log的結果:
07-02 23:48:24.195 6278-6278/com.example.widget V/Test: Ok lets see
07-02 23:48:24.205 6278-6278/com.example.widget V/Test: t=test
07-02 23:48:24.205 6278-6278/com.example.widget V/Test: Ok...t=test
if(t=="test") t="tada";
改成
if(t.equals("test")) t="tada";