简体   繁体   中英

How do I open an Android app straight to an activity that is not the main activity and later move to the main activity?

The following is my mainActivity - up to the onCreate function, without the imports. I defined this as most of my activities parent. I want my app to open on the login activity - ao the user will login before using the app. After they log in, I want this activity to open.

public class MainActivity extends AppCompatActivity
    implements NavigationView.OnNavigationItemSelectedListener {

public final String APP_TAG = "MyCustomApp";
public final static int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 1034;
public String photoFileName = "photo.jpg";
public final int MY_PERMISSIONS_REQUEST_CAMERA = 66;
public static final int MEDIA_TYPE_IMAGE = 1;
public static final int MEDIA_TYPE_VIDEO = 2;
private static final int CAMERA_REQUEST = 1888;

final int REQUEST_LOG_IN = 666;

FirebaseDatabase database = FirebaseDatabase.getInstance();
String m_Text;
User user = null;
DatabaseReference myRef;
DatabaseReference userRef;


@Override
protected void onCreate(Bundle savedInstanceState)
{

    //default text
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
        this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    tryGetUser();
}

The following is my LoginActivity - up to the onCreate function, without the imports. Which I want to be the first page to open

public class LoginActivity extends BaseActivity implements LoaderCallbacks<Cursor> {


final int RC_SIGN_IN = 101;

final int REQUEST_LOG_IN = 666;

/**
 * Id to identity READ_CONTACTS permission request.
 */
private static final int REQUEST_READ_CONTACTS = 0;

/**
 * Keep track of the login task to ensure we can cancel it if requested.
 */
private UserLoginTask mAuthTask = null;

// UI references.
private AutoCompleteTextView mEmailView;
private EditText mPasswordView;
private View mProgressView;
private View mLoginFormView;
private FirebaseAuth mAuth;

private GoogleApiClient mGoogleApiClient;

@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);

    mAuth = FirebaseAuth.getInstance();

    setContentView(R.layout.activity_login);
    // Set up the login form.
    mEmailView = (AutoCompleteTextView) findViewById(R.id.email);
    populateAutoComplete();

    mPasswordView = (EditText) findViewById(R.id.password);
    mPasswordView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) {
            if (id == R.id.login || id == EditorInfo.IME_NULL) {
                attemptLogin();
                return true;
            }
            return false;
        }
    });

Just set that activity as the launcher activity on the manifest instead of the default main activity.

PS: Please elaborate​ your question and post code not screenshots. How do you want help if you can't help yourself to be understood?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM