在我的應用程序,我有一個進入活動(空,沒有佈局),檢查賬戶的客戶經理:在onCreate()中開始另一個活動?
- 如果存在一個帳戶某些類型的:開始的主要活動
- 否則, 開始的活動獲得用戶憑據(將其添加到帳戶)
這裏是在EntryActivity
代碼:
public class EntryActivity extends Activity {
// Tag
private String TAG = getClass().getSimpleName();
// Inst.
private AccountManager accountManager;
private Account[] accounts;
private Authenticator authenticator;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
authenticator = new Authenticator(this);
// Check for the account in account manager
accountManager = AccountManager.get(this);
accounts = accountManager.getAccountsByType(HConstants.ACCOUNT_TYPE);
int nAccounts = accounts.length;
if(nAccounts!=0){
// There's an account
}
else{
// Prompt user to enter creds
final Intent intent = new Intent(this, AuthenticationActivity.class);
startActivity(intent);
}
}
的問題是,我無法啓動AuthenticationActivity
和我得到這個錯誤:
java.lang.IllegalStateException: System services not available to Activities before onCreate()
我怎樣才能解決這個問題?
更新:代碼AuthenticationActivity
:
public class AuthenticationActivity extends Activity {
// Instances
AccountManager accountManager = AccountManager.get(this);
// Values for email and password at the time of the login attempt.
private String mEmail;
private String mPassword;
// UI references.
private EditText mEmailView;
private EditText mPasswordView;
private View mLoginFormView;
private View mLoginStatusView;
private TextView mLoginStatusMessageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.authentication_activity);
// Set up the login form.
mEmailView = (EditText) findViewById(R.id.email);
mEmailView.setText(mEmail);
mPasswordView = (EditText) findViewById(R.id.password);
mLoginFormView = findViewById(R.id.login_form);
mLoginStatusView = findViewById(R.id.login_status);
mLoginStatusMessageView = (TextView) findViewById(R.id.login_status_message);
}
你的'setContentView'在哪裏? – Raghunandan
@Raghunandan,我沒有。這基本上是啓動其他人的無形活動。 – Mahm00d
AuthenticationActivity是否擴展了Activity? – Blackbelt