0

我一直在阅读 Android 网站上开发文档中的示例代码,特别是:

http://developer.android.com/resources/samples/SampleSyncAdapter/src/com/example/android/samplesync/authenticator/AuthenticatorActivity.html

这是示例应用程序的唯一活动。它指的是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);

这是与意图一起工作的代码块。为什么你会对应用程序中的唯一活动有意图?这个应用程序是否以不寻常的方式调用?清单不包括活动的意图过滤器......我想我只是对这整件事有点迷失了!如果有人能让我直截了当,那就太好了,谢谢。

4

2 回答 2

1
  1. Why would you have an intent for the only activity in the app?

    getIntent() gets you the intent that started this activity.

  2. 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.. and getExtra.. is a way to pass data between activities when they are started.

于 2011-03-05T23:31:18.013 回答
0

在该特定示例中,意图是从Authenticator.java中的 addAccount 方法发送的。当您单击“帐户和同步设置”屏幕中的“添加帐户”按钮并选择您的帐户类型时,操作系统会调用该方法。

于 2011-06-21T14:53:04.937 回答