[英]Passing data from intent service to activity
我有一个广播接收器从中调用intentservice.I想要将intentservice中收到的数据发送到activity.String s = extras.getString(“Notice”)。我想将这个收到的字符串发送到一个新的活动
@Override
protected void onHandleIntent(Intent arg0) {
Intent dialogIntent = new Intent(getBaseContext(), myActivity.class);
dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
dialogIntent.putExtra("value", extras.getString("Notice"));
getApplication().startActivity(dialogIntent);
}
public class YourIntentService extends IntentService {
@Override
protected void onHandleIntent(Intent arg0) {
// TODO Auto-generated method stub
Intent intent = new Intent(this, YourNewActivity.class);
intent.putExtra("YourStringKey", "yourString");
startActivity(intent);
}
public YourIntentService() {
super("YourIntentService");
}
}
Try this. 试试这个。 Sorry for misunderstanding. 我为我的误会道歉。
public class MyIntentService extends IntentService {
public MyIntentService() {
super(" MyIntentService");
}
@Override
protected void onHandleIntent(Intent arg0) {
String s=arg0.getExtras.getString("Notice")
Intent i = new Intent(this, yourActivity.class);
i.putExtra("Notice",s);
getApplication().startActivity(i);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.