
调用代码(在服务中运行):
Intent textIntent = new Intent(this, TextActivity.class);textIntent.putExtra("text_seq", message.xfer.seq);textIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);startActivity(textIntent);调用代码(在TextActivity中):
@OverrIDeprotected voID onCreate(Bundle bundle) { super.onCreate(bundle); Log.d(TAG, "" + bundle.getInt("text_seq")) ...实际上整个包都丢失了 – 上面的代码在调用bundle.getInt()时会抛出一个NPE.
我确信有一些我错过的东西……
解决方法:
你正在阅读的捆绑不是为了那个目的.如per docs
voID onCreate (Bundle savedInstanceState)Bundle: If the activity is being re-initialized after prevIoUsly being
shut down then this Bundle contains the data it most recently supplIEd
in onSaveInstanceState(Bundle). Note: Otherwise it is null.
如果你需要额外的东西,你需要打电话:
Bundle extras = getIntent().getExtra();然后你可以尝试获得你的价值观:
int myVal = extras.getInt(key);或者你可以尝试使用:
int myVal = getIntent().getIntExtra(key, defaultVal); 总结 以上是内存溢出为你收集整理的android – 从服务启动的Activity从包中丢失了“额外”全部内容,希望文章能够帮你解决android – 从服务启动的Activity从包中丢失了“额外”所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)