在loginactivity的条件下启动活动

时间:2016-10-16 16:19:04

标签: android

如果用户在数据库条目中处于活动状态,我想在登录后启动活动我希望在用户未激活的情况下启动MainActivity.java它应该启动移动验证屏幕我正在使用凌空来进行http调用并从中获取数据这里的服务器是我的脚本

LoginActivity.java

// Now store the user in SQLite
                    String uid = jObj.getString("uid");

                    JSONObject user = jObj.getJSONObject("user");
                    String name = user.getString("name");
                    String email = user.getString("email");
                    String phone = user.getString("phone");
                    String status = user.getString("status");


                    // Inserting row in users table
                    db.addUser(name, email, uid,phone);
                    if(new String(status).equals("active") ) {
                        // Launch main activity
                        Intent intent = new Intent(LoginActivity.this,
                                MainActivity.class);
                        startActivity(intent);
                        finish();
                    } else{

                        Intent intent = new Intent(LoginActivity.this, MainActivity.class);
                        startActivity(intent);
                        finish();
                    }

2 个答案:

答案 0 :(得分:0)

问题是你是以错误的方式比较两个字符串。你应该编辑

if(new String(status).equals("active") )

为:

if(status.contentEquals("active"))

你已经完成了。

答案 1 :(得分:0)

String uid = jObj.getString(“uid”);

                JSONObject user = jObj.getJSONObject("user");
                String name = user.getString("name");
                String email = user.getString("email");
                String phone = user.getString("phone");
                String status = user.getString("status");


                // Inserting row in users table
                db.addUser(name, email, uid,phone);
                if(new String(status).equals("active") ) {
                    // Launch main activity
                    Intent intent = new Intent(LoginActivity.this,
                            MainActivity.class);
                    startActivity(intent);
                    finish();
                } else{

                    Intent intent = new Intent(LoginActivity.this, Verifyotp.class);
                    startActivity(intent);
                    finish();
                }