安卓:用户登录,并停留在会议上,直至注销(其中需审批) [英] Android: user login and stays in session until logout (which needs approval)

查看:114
本文介绍了安卓:用户登录,并停留在会议上,直至注销(其中需审批)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想确保当用户登录它会留在会议上无论发生什么事(应声,关机/关机/重启,使应用程序)的同时,用户的信息数据将全部被发送该活动的应用程序到Web服务器。

例如在启动时的应用程序,用户登陆'9999'它去的有5个差异的主要活动。活动。用户9999将发送一个活动(即GPS位置),它会发送信息到Web服务器的用户9999的GPS 123.234 123.123。

我要确保用户停留在会议上,也有送活动的数据发送其用户的数据。 我读了这个链接

<一个href="http://stackoverflow.com/questions/785973/what-is-the-most-appropriate-way-to-store-user-settings-in-android-application">What是最合适的方式来存储在Android应用程序用户设置

我仍然无法把它一起。

目前同时在同一主屏幕它有一个注销。用户需要经理审批通过输入code(即1234)彻底退出和新用户输入自己的身份证号码注销。我想知道如何把硬code'1234'的活动中。

这code是我的主屏幕登录后,给你的想法

  MainActivity.java

 进口android.app.ListActivity;
 进口android.content.Intent;进口
 android.os.Bundle;进口
 android.view.View;进口
 android.widget.ArrayAdapter;进口
 android.widget.ListView;进口
 android.widget.TextView;

 公共类客户扩展ListActivity {TextView的选择;
     CustomerListItem []项目= {
          新CustomerListItem(启动之旅,StartTripActivity.class)
         新CustomerListItem(时钟在ClockinActivity.class)
         新CustomerListItem(客户SVC,CustomerSvcActivity.class)
         新CustomerListItem(IndependentInspection,InspectionActivity.class)
         新CustomerListItem(拿起,PickUpActivity.class)
         新CustomerListItem(注销,LogoutActivity.class)};

私人TextView的resultsTxt;

     @覆盖
     公共无效的onCreate(包冰柱)
     {
         super.onCreate(冰柱);
         的setContentView(R.layout.main);
         setListAdapter(新ArrayAdapter&LT; CustomerListItem&GT;(
                 对此,android.R.layout.simple_list_item_1,
 项));
         选择=(TextView中)findViewById(R.id.selection);
     }

     @覆盖
     保护无效onListItemClick(ListView的L,视图V,
 INT位置,长ID)
     {
         super.onListItemClick(L,V,位置ID);
         最终意向意图=新的意图(这一点,
 项目[位置] .getActivity());
         startActivityForResult(意向,位置);
     }

     @覆盖
     保护无效onActivityResult(INT申请code,INT
 因此code,意图意图)
     {
         super.onActivityResult(要求code,
 因此code,意图);
         如果(结果code == RESULT_OK)
         {
             //基于来自其活性执行不同的动作
             //应用程序返回:
             开关(要求code)
             {
                情况下0:
            // TODO:处理StartTripActivity返回
            打破;
        情况1:
            // TODO:处理ClockinActivity返回
            打破;
        案例2:
            // TODO:处理CustomerSvcActivity返回
        案例3:
            // TODO:处理InspectionActivity返回
            打破;
        壳体4:
            // TODO:处理PickUpActivity返回
            打破;
        壳体5:
            // TODO:处理LogoutActivity返回
            打破;
        默认:
            打破;
             }
         }
         否则,如果(结果code == RESULT_CANCELED)
         {
             resultsTxt.setText(取消);
         }
     }}
 

更新:

Login.java

 进口android.app.Activity;
进口android.content.Intent;
进口android.os.Bundle;
进口android.view.View;
进口android.view.View.OnClickListener;
进口android.widget.Button;
进口android.widget.EditText;
进口android.widget.TextView;


公共类登录扩展活动{
    私人的EditText etUsername;
    私人按钮btnLogin;
    私人按钮btnCancel;
    私人TextView的lblResult;
    / **第一次创建活动时调用。 * /
    // @覆盖
    公共无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.login);

        etUsername =(EditText上)findViewById(R.id.username);
        btnLogin =(按钮)findViewById(R.id.login_button);
        btnCancel =(按钮)findViewById(R.id.cancel_button);
        lblResult =(TextView中)findViewById(R.id.result);

        btnLogin.setOnClickListener(新OnClickListener(){
            // @覆盖
            公共无效的onClick(视图v){
            //检查登录
            字符串username = etUsername.getText()的toString()。

            如果(username.equals(客户)){
                lblResult.setText(登录成功);




                意图I =新的意图(getApplicationContext(),Customer.class);
                startActivity(ⅰ);

            } 其他 {
                 lblResult.setText(登录失败用户名不匹配。);
             }
            }
            });


            btnCancel.setOnClickListener(新OnClickListener(){
            // @覆盖
            公共无效的onClick(视图v){
               //关闭应用程序
            完();
                }
            });
    }
}
 

解决方案

您包含的链接显示,以存储用户的ID的方式 - 你可以使用的共享preferences 的,也可以将其存储的数据库

您可以存储审批code的任何地方。如果你想硬$ C C是$,您可能希望把它放在一个静态的辅助类的公共静态最后弦乐变量。

I would like to make sure that when user log in it will stay in session no matter what happens (crashed, shut down/power down/reboot, leaving the app) at same time the user info data will be sending with all the activities in the app to the webserver.

for example at the start up of the app, user login '9999' it goes to the main activity that have 5 diff. activities. user 9999 will send one activity (i.e. gps location) it will send that info to the webserver as user 9999 gps 123.234 123.123.

I want to ensure the users stays in session and also send its users data with the "activity" data sent. I read this link

What is the most appropriate way to store user settings in Android application

I was still unable to put it together.

At the same time in the same main screen it has a logout. User needs manager approval to logout by inputting the code(i.e. 1234) to completely logout and for new user to input their id number. I want to know how to put the hardcode '1234' within the activity.

this code is my main screen after login to give you the idea

 MainActivity.java

 import android.app.ListActivity;
 import android.content.Intent; import
 android.os.Bundle; import
 android.view.View; import
 android.widget.ArrayAdapter; import
 android.widget.ListView; import
 android.widget.TextView;

 public class Customer extends ListActivity {TextView selection;
     CustomerListItem[] items ={
          new CustomerListItem("Start Trip",StartTripActivity.class), 
         new CustomerListItem("Clock in",ClockinActivity.class), 
         new CustomerListItem("Customer Svc",CustomerSvcActivity.class), 
         new CustomerListItem("IndependentInspection",InspectionActivity.class), 
         new CustomerListItem("Pick Up", PickUpActivity.class), 
         new CustomerListItem("Log Out", LogoutActivity.class)};    

private TextView resultsTxt;

     @Override
     public void onCreate(Bundle icicle)
     {
         super.onCreate(icicle);
         setContentView(R.layout.main);
         setListAdapter(new ArrayAdapter<CustomerListItem>(
                 this, android.R.layout.simple_list_item_1,
 items));
         selection = (TextView) findViewById(R.id.selection);
     }

     @Override
     protected void onListItemClick(ListView l, View v,
 int position, long id)
     {
         super.onListItemClick(l, v, position, id);
         final Intent intent = new Intent(this,
 items[position].getActivity());
         startActivityForResult(intent, position);
     }

     @Override
     protected void onActivityResult(int requestCode, int
 resultCode, Intent intent)
     {
         super.onActivityResult(requestCode,
 resultCode, intent);
         if (resultCode == RESULT_OK)
         {
             // Perform different actions based on from which activity is
             // the application returning:
             switch (requestCode)
             {
                case 0:
            // TODO: handle the return of the StartTripActivity
            break;
        case 1:
            // TODO: handle the return of the ClockinActivity
            break;
        case 2:
            // TODO: handle the return of the CustomerSvcActivity
        case 3:
            // TODO: handle the return of the InspectionActivity
            break;
        case 4:
            // TODO: handle the return of the PickUpActivity
            break;
        case 5:
            // TODO: handle the return of the LogoutActivity
            break;
        default:
            break;
             }
         }
         else if (resultCode == RESULT_CANCELED)
         {
             resultsTxt.setText("Canceled");
         }
     } }

UPDATE:

Login.java

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;


public class Login extends Activity {
    private EditText etUsername;
    private Button btnLogin;
    private Button btnCancel;
    private TextView lblResult;
    /** Called when the activity is first created. */
    //@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);

        etUsername = (EditText)findViewById(R.id.username);
        btnLogin = (Button)findViewById(R.id.login_button);
        btnCancel = (Button)findViewById(R.id.cancel_button);
        lblResult = (TextView)findViewById(R.id.result);

        btnLogin.setOnClickListener(new OnClickListener() {
            //@Override
            public void onClick(View v) {
            // Check Login
            String username = etUsername.getText().toString();

            if(username.equals("guest")){
                lblResult.setText("Login successful.");




                Intent i = new Intent(getApplicationContext(), Customer.class);
                startActivity(i);

            } else {
                 lblResult.setText("Login failed. Username doesn't match.");
             }
            }
            });


            btnCancel.setOnClickListener(new OnClickListener() {
            //@Override
            public void onClick(View v) {
               // Close the application
            finish();
                }
            });
    }
}

解决方案

The link you included shows the way to store the user's ID - you can use SharedPreferences or you can store it in the database.

You can store the "approval code" anywhere. If you want to hard-code it, you may want to put it in a "static" helper class in a public static final String variable.

这篇关于安卓:用户登录,并停留在会议上,直至注销(其中需审批)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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