有关 Android 上帐户创建和同步的问题
我一直在阅读 Android 网站上的开发文档中的示例代码,特别是:
这是示例应用程序的唯一活动。它引用 onCreate
方法中的意图。我不明白这个意图来自哪里,或者如果这是应用程序使用的唯一活动,它应该包含什么。
Log.i(TAG, "loading data from Intent");
final Intent intent = getIntent();
mUsername = intent.getStringExtra(PARAM_USERNAME);
mAuthtokenType = intent.getStringExtra(PARAM_AUTHTOKEN_TYPE);
mRequestNewAccount = mUsername == null;
mConfirmCredentials = intent.getBooleanExtra(PARAM_CONFIRM_CREDENTIALS, false);
这是处理意图的代码块。为什么您会对应用程序中的唯一活动有意图?这个应用程序的调用方式是否不寻常?清单不包括活动的意图过滤器...我想我对整个事情有点迷失了!如果有人能纠正我的话那就太好了,谢谢。
I've been reading the sample code from the dev docs on Android's site, specifically this:
Which is the sole activity of the sample app. It refers to an intent in the onCreate
method. I don't understand where this intent is coming from, or what it should contain if this is the only activity the app utilizes.
Log.i(TAG, "loading data from Intent");
final Intent intent = getIntent();
mUsername = intent.getStringExtra(PARAM_USERNAME);
mAuthtokenType = intent.getStringExtra(PARAM_AUTHTOKEN_TYPE);
mRequestNewAccount = mUsername == null;
mConfirmCredentials = intent.getBooleanExtra(PARAM_CONFIRM_CREDENTIALS, false);
That's the block of code working with the intent. Why would you have an intent for the only activity in the app? Is this app called in an unusual way? The Manifest does not include an intent filter for the activity... I guess I'm just a bit lost on this whole thing! If someone could set me straight that'd be great, thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么您会对应用中的唯一活动有意图?
getIntent()
获取启动此活动的意图。此应用程序的调用方式是否异常?
我猜这个活动是从另一个应用程序或活动以编程方式调用的,因为它已经传递了一些额外的数据:
getStringExtra()
用于从启动它的意图中提取一些数据。putExtra..
和getExtra..
是一种在 Activity 启动时在 Activity 之间传递数据的方法。Why would you have an intent for the only activity in the app?
getIntent()
gets you the intent that started this activity.Is this app called in an unusual way?
I guess this activity is called programmatically from another app or activity, since it has been passed some extra data:
getStringExtra()
is used to extract some data from the intent that started it.putExtra..
andgetExtra..
is a way to pass data between activities when they are started.在该特定示例中,意图是从
In that specific example, the intent is sent from the addAccount method in Authenticator.java. That method is called by the OS when you click the Add Account button in the Accounts & sync settings screen and choose your account type.