我已从主要活动开始另一项活动,但该方法无效

时间:2017-10-11 12:33:23

标签: android android-intent

我试图通过" 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);

请帮忙。

1 个答案:

答案 0 :(得分: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>