I'm building some sort of wizard to create user accounts in Sync and Manage account. I use a ViewFlipper my activity has to be an AccountAuthenticatorActivity. That said it also means I can't inherit PreferenceActivity.
So I looked up in the code of PreferenceActivity and I believe it should be possible to have a PreferenceView that inherit from ListView. The Activity part of PreferenceActivity isn't really needed as far as I know.
Though the PreferenceManager is what really blocks me.
private PreferenceManager onCreatePreferenceManager() {
PreferenceManager preferenceManager = new PreferenceManager(this, FIRST_REQUEST_CODE);
preferenceManager.setOnPrefe开发者_StackOverflow中文版renceTreeClickListener(this);
return preferenceManager;
}
This function imply that we can instatiate PreferenceManager using the operator new. Apparently, the sdk hide the constructor of the PreferenceManager. I'm kind of confused.
Is there a way to inflate my preferences and display them without PreferenceActivity?
Is there a way to inflate my preferences and display them without PreferenceActivity?
Not via the SDK, AFAIK.
Since you are neither showing nor modifying preferences in this wizard ("I'm building some sort of wizard to create user accounts in Sync and Manage account"), I have no idea why you would want to use Preference
objects, anyway. Just use regular widgets.
Yes, the initiator may need to be an AccountAuthenticatorActivity
but I presume that, in turn, can start any activity it would like. The AccountAuthenticatorActivity
douesn't necessarily have to show its own GUI.
This is how we do it; receive the addAccount
request which kicks off a preference activity. The intent is parsed to see if a new account is requested and the appropriate GUI is shown. When the wizard is done, the resulting account is passed back to AccountAuthenticatorActivity
via the result Intent
.
/*
* The user has requested to add a new account to the system. We return
* an intent that will launch our login screen if the user has not
* logged in yet, otherwise our activity will just pass the user's
* credentials on to the account manager.
*/
@Override
public Bundle addAccount(AccountAuthenticatorResponse response,
String accountType, String authTokenType,
String[] requiredFeatures, Bundle options)
throws NetworkErrorException {
Bundle result = new Bundle();
Intent i = new Intent(mContext, PrefsActivity.class);
i.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE,
response);
i.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT,
ServerPrefsFragment.class.getName());
result.putParcelable(AccountManager.KEY_INTENT, i);
return result;
}
EDIT: Just realized I didn't exactly answer the question. The solution we've chosen to do what you want is actually as suggested below; not using a PreferenceActivity for the wizard but a standard activity called by the addAccount function shown above.
精彩评论