2017-10-11 64 views
-3

我試圖通過「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> 

問題是無法在該行開始活動 意圖registerIntent =新意圖(LoginActivity.this,Register.class );

請幫助。

+1

如果你得到一個錯誤,只是貼吧。 –

回答

0

你有兩個LAUNCHER活動,只要註冊活動爲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> 
+0

根據評論更改了代碼,但沒有結果。意圖不開始。 –

相關問題