最近我一直在尝试使用Intent.putExtra()将简单的字符串数据从Service传递到Activity,但是一直没有成功。无论如何,Intent.getStringExtra()总是NULL。
SERVICE代码:
Intent intent=new Intent(getBaseContext(),MainActivity.class);
intent.putExtra(Consts.INTERNET_ERROR, "error");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplication().startActivity(intent);
活动代码:
public void onResume() {
super.onResume();
Intent i = getIntent();
String test = "temp";
Bundle b = i.getExtras();
if (b != null) {
test = b.getString(Consts.INTERNET_ERROR);
}
}
有什么建议吗?