簡體   English   中英

我從主要活動開始了另一項活動,但該方法不起作用

[英]I have start another activity from main activity but the method not working

我正在嘗試通過“checkDirectory”調用從內部存儲讀取文件,然后如果未找到數據,則調用注冊類程序進行注冊。 問題是 startActivity(registerIntent) 沒有啟動。

公共類 LoginActivity 擴展 AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.loginscreen);
    // Set up the login form.
    mPhoneView = (EditText) findViewById(R.id.PhoneNumber);
    //populateAutoComplete();

    mPasswordView = (EditText) findViewById(R.id.Password);
    Button mEmailSignInButton = (Button) findViewById(R.id.SignIn);
    mEmailSignInButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            attemptLogin();
        }
    });
}

 */
private void attemptLogin() {

    if (cancel) {
        focusView.requestFocus();
    } else {
        // Show a progress spinner, and kick off a background task to
        // perform the user login attempt.
        //  showProgress(true);
        String messg = UserLoginTask(phone, password);
        mPhoneView.setError(messg);
        focusView = mPhoneView;
        Intent logindetails = new Intent(LoginActivity.this, MechanicScreen.class);
        logindetails.putExtra("phone_number", phone);
        startActivity(logindetails);
    }
}

protected boolean login_password_valid(String mphone, String mpassword, int validno) {
    boolean cancel = false;
    View focusView = null;
    String firstLine = null;
    String secondLine = null;
    fPath = retValue[2];
    String line;
        try {
            if (firstLine == null) {
                try {
                    Intent registerIntent = new Intent(LoginActivity.this, Register.class);
                    startActivity(registerIntent);
                } catch (Exception e) {
                    e.printStackTrace();
                }

            }
public String UserLoginTask(String phone, String password) {
    //CheckDirectoryIntExt dirCheck = new CheckDirectoryIntExt();
    retValue = checkDirectory(dName, fName);
    //retValue = dirCheck.checkDirectory(dName, fName);
    if (retValue[0] == null) {
        if (login_password_valid(phone, password, Customer_valid)) {
            Customer_valid = 1;
            System.out.println("First In");
            startActivity(new Intent(getApplicationContext(), MechanicScreen.class));
        } else {
            return "Invalid Username or Password";
        }
    } else {
        return "Error in the Directory Setup";
    }
    return null;
}

清單是

    <activity
        android:name="omsairam.servicingrepair.LoginActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="omsairam.servicingrepair.Register"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.GET_CONTENT" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="omsairam.servicingrepair.MechanicScreen"
        android:label="@string/app_name" >
    </activity>
</application>

問題是無法在 Intent registerIntent = new Intent(LoginActivity.this, Register.class); 行啟動活動。

請幫忙。

您有兩個 LAUNCHER 活動,只需將 Register Activity 設置為 DEFAULT

<activity
    android:name="omsairam.servicingrepair.Register"
    android:label="@string/app_name" >
    <intent-filter>
        <action android:name="android.intent.action.GET_CONTENT" />
        <category android:name="android.intent.category.DEFAULT" /> //This line...
    </intent-filter>
</activity>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM