目前共有14篇帖子。 內容轉換:不轉換▼
 
點擊 回復
327 13
今天我正在製作app的用戶登錄功能
一派護法 十九級
1樓 發表于:2015-5-9 23:57
用sharedpreference
一派護法 十九級
2樓 發表于:2015-5-9 23:57
sp = context.getSharedPreferences("ArslanbarPreferences", Context.MODE_PRIVATE);
一派護法 十九級
3樓 發表于:2015-5-9 23:58
這就比存入普通文件安全多了,也簡單多了
至少不用訪問內存卡
也不用擔心其他程序能讀取數據造成安全隱患
一派護法 十九級
4樓 發表于:2015-5-9 23:59
public static void makeToast(String text, int duration) {
        Toast.makeText(context, text, duration).show();
    }

    public static void makeToast(String text) {
        makeToast(text, Toast.LENGTH_SHORT);
    }

    public static void makeToast(int stringId) {
        makeToast(res.getString(stringId));
    }
一派護法 十九級
5樓 發表于:2015-5-9 23:59
public static void showNumberDialog(String title, String content, int number) {
        ViewGroup parent = null;
        View view = getLayoutInflater().inflate(R.layout.input_number, parent);
        TextView tv = (TextView)view.findViewById(R.id.text);
        tv.setText(content);
        final EditText et = (EditText)view.findViewById(R.id.number);
        et.setText(number + "");
        
        Dialog dlg = new AlertDialog.Builder(context)
            .setTitle(title)
            .setView(view)
            .setPositiveButton(res.getString(R.string.button_OK), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // TODO Auto-generated method stub
                    listener.text = et.getText().toString();
                    listener.number = Integer.parseInt(listener.text);
                    listener.onOK();
                    listener = null;
                }
            })
            .setNegativeButton(res.getString(R.string.button_cancel), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // TODO Auto-generated method stub
                    listener.text = et.getText().toString();
                    listener.number = Integer.parseInt(listener.text);
                    listener.onCancel();
                    listener = null;
                }
            })
            .create();
        dlg.show();
    }
一派護法 十九級
6樓 發表于:2015-5-9 23:59
showNumberDialog取消了listener參數
一派護法 十九級
7樓 發表于:2015-5-10 00:00
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.arslanbar.LoginActivity" >

    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginBottom="16dp"
        android:layout_marginTop="32dp"
        android:text="@string/title_activity_login"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <TextView
        android:id="@+id/content"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/login_username" />

    <EditText
        android:id="@+id/user_name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="text" >

        <requestFocus />
    </EditText>

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:text="@string/login_password" />

    <EditText
        android:id="@+id/user_password"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="textPassword" />

    <RelativeLayout
        android:id="@+id/RelativeLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center" >

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:layout_alignParentStart="true"
            android:text="@string/button_OK" />

        <Button
            android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBaseline="@+id/button1"
            android:layout_alignParentTop="true"
            android:layout_toRightOf="@+id/button1"
            android:layout_toEndOf="@+id/button1"
            android:text="@string/button_cancel" />
    </RelativeLayout>

</LinearLayout>

一派護法 十九級
8樓 發表于:2015-5-10 00:01
network.URLParams = "query=login";
                network.params.add(new BasicNameValuePair("UserName", userName));
                network.params.add(new BasicNameValuePair("Password", App.MD5(password)));
                network.handler = new networkHandler();
                network.send();
一派護法 十九級
9樓 發表于:2015-5-10 00:01
BasicNameValuePair
一派護法 十九級
10樓 發表于:2015-5-11 22:47
我覺得還是UserKey 制度比較好,不該用Session+UserKey制度
一派護法 十九級
11樓 發表于:2015-5-11 22:49
Session不利於Userkey的生成與註銷
初級魔法師 四級
12樓 發表于:2015-5-11 23:39
第9行我习惯用

AlertDialog.Builder ad =

回复:5楼

一派護法 十九級
13樓 發表于:2015-5-12 23:11
回復:12樓
感覺都差不多。。。
一派護法 十九級
14樓 發表于:2015-5-12 23:18
我打算取消session制度

回復帖子

內容:
用戶名: 您目前是匿名發表
驗證碼:
(快捷鍵:Ctrl+Enter)
 

本帖信息

點擊數:327 回複數:13
評論數: ?
作者:巨大八爪鱼
最後回復:巨大八爪鱼
最後回復時間:2015-5-12 23:18
 
©2010-2024 Arslanbar Ver2.0
除非另有聲明,本站採用創用CC姓名標示-相同方式分享 3.0 Unported許可協議進行許可。