当用户退出我不点击注销按钮Android应用的用户仍然的loggedIn出现在我的在线数据库 [英] when a user exit my android app without clicking logout button the user still appears loggedin in my online database

查看:94
本文介绍了当用户退出我不点击注销按钮Android应用的用户仍然的loggedIn出现在我的在线数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户退出我的Andr​​oid应用程序无需点击注销按钮,用户仍然出现登录我的在线数据库,当他再次打开该应用程序,他将被定向到登录页面,并因为他自己无法登录显示在数据库登录,请我该如何解决这个问题,我使用日志中的1和0的形式。谢谢

when a user exit my android app without clicking log out button the user still appears logged in in my online database, when next he opens the app he will be directed to the log in page and he can't log in since he appears logged in in the database, please how do i solve this problem, am using the 1 and 0 form of log in. thanks

enter code here

公共类MainActivity延伸活动{

public class MainActivity extends Activity {

private EditText username;
private EditText password;
private TextView reg;
//private TextToSpeech myTTS;
    //status check code
//private int MY_DATA_CHECK_CODE = 0;

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

    setContentView(R.layout.activity_main);
    reg = (TextView)findViewById(R.id.reger);

      username = (EditText)findViewById(R.id.UserText1);
     password = (EditText)findViewById(R.id.PassText2);
  // String Userid;
    //String Passid= password.toString();
    Button login = (Button)findViewById(R.id.login);
    login.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
              final SharedPreferences userid = getSharedPreferences("prefs",0);
            ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
            postParameters.add(new BasicNameValuePair("username", username.getText().toString()));
            postParameters.add(new BasicNameValuePair("password", password.getText().toString()));
            postParameters.add(new BasicNameValuePair("login", "1"));
            String response = null;
            try {
                response = CustomHttpClient.executeHttpPost("http://www.website.com/login4.php", postParameters);
                String res=response.toString();
                res = res.trim();
                res= res.replaceAll("\\s+","");   
                //reg.setText(res);
                //error.setText(res);
                if(username.getText().toString().equals("") || password.getText().toString().equals("")){

                    reg.setText("Sorry!! Incorrect Username or Password"); 
                }
                else if(res.equals(username.getText().toString()+password.getText().toString())){
                    SharedPreferences.Editor editor = userid.edit();
                    editor.putString("username", username.getText().toString());
                    editor.putString("password", password.getText().toString());
                    editor.commit();
                    //speakWords("You are logged in succesfully");

                startActivity(new Intent(MainActivity.this, HomePage.class));
                }

                else {

                    reg.setText(res);
                }
            } catch (Exception e) {
                reg.setText("You have a network failure");
            }

        }
    });


    reg.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent intent = new Intent(MainActivity.this, Registration.class);
            startActivity(intent);
        }
    });
    TextView freeview =(TextView)findViewById(R.id.Samp);
    freeview.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent intent = new Intent(MainActivity.this, Sample_year.class);
            startActivity(intent);
        }
    });
}

//设置SystemUiHider的实例来控制的系统UI
}

// Set up an instance of SystemUiHider to control the system UI for }

推荐答案

在活动类的onStop()方法被称为当用户从应用程序导航走的值更改为0!

change the value to 0 in the onStop() method of the activity class which is called when your user navigates away from the app!

这篇关于当用户退出我不点击注销按钮Android应用的用户仍然的loggedIn出现在我的在线数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆