)从savedInstanceState getIntent(之间的差,并获得意图是什么? [英] What is the difference between getIntent() and getting intent from savedInstanceState?

查看:434
本文介绍了)从savedInstanceState getIntent(之间的差,并获得意图是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我尝试了主意,2类之间的android的传球和我已经意识到有2种方法来传递意图,

Hi all I'm trying out the android passing of intents between 2 classes and I've realized there are 2 methods to passing intents ,

首先是用getIntent方法在这里:

The first is using getIntent method here:

Bundle extras = getIntent().getExtras();
mRowId = (extras != null) ? extras.getLong(DrugsDbAdapter.KEY_ROWID) : null;

和第二种方法被访问savedInstanceState:

And the second method is accessing the savedInstanceState:

mRowId = (savedInstanceState != null) savedInstanceState.getLong(DrugsDbAdapter.KEY_ROWID) : null;

在这两种方法,我试图访问其rowid,我就可以用它来fetchData。请告诉我这两种方法之间的区别是什么?哪一个更好呢?

In both methods I'm trying to access the RowId which I can then use to fetchData. Whats the difference between both methods ? Which one is better ?

推荐答案

第一种情况为您提供了启动这一活动,而第二个则使用意图的临时演员时,的onCreate 调用第二和更多的时间,例如,在设备旋转。这束应的onSaveInstanceState 进行填充。

The first case gives you the extras of the intent that started this activity, while the second one is used when onCreate is invoked the 2nd and more time, for example, on device rotate. That bundle should be populated in onSaveInstanceState.

这篇关于)从savedInstanceState getIntent(之间的差,并获得意图是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆