开发者

Question regarding account creation and sync on Android

开发者 https://www.devze.com 2023-02-15 14:04 出处:网络
I\'ve been reading the sample code from the dev docs on Android\'s site, specifically this: http://developer.android.com/resources/samples/SampleSyncAdapter/src/com/example/android/samplesync/authent

I've been reading the sample code from the dev docs on Android's site, specifically this:

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

Which is the sole activity of the sample app. It refers to an intent in the onCreate method. I don't understand w开发者_JAVA技巧here 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.


  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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消