#2
vvvevvv2016-02-27 10:49
|
程序代码:
package gzy.secret;
import android.content.Context;
import android.content.SharedPreferences;
public class Config {
public static final String KEY_TOKEN="token";
public static final String APP_ID="gzy.secret";
public static String getCachedTOken(Context context){
return context.getSharedPreferences(APP_ID,Context.MODE_PRIVATE).getString(KEY_TOKEN,null);
}
public static void cacheToken(Context context,String token){
SharedPreferences.Editor e=context.getSharedPreferences(APP_ID,Context.MODE_PRIVATE).edit();
();
}
}
import android.content.Context;
import android.content.SharedPreferences;
public class Config {
public static final String KEY_TOKEN="token";
public static final String APP_ID="gzy.secret";
public static String getCachedTOken(Context context){
return context.getSharedPreferences(APP_ID,Context.MODE_PRIVATE).getString(KEY_TOKEN,null);
}
public static void cacheToken(Context context,String token){
SharedPreferences.Editor e=context.getSharedPreferences(APP_ID,Context.MODE_PRIVATE).edit();
();
}
}
//这些是什么意思,我有些糊涂!
程序代码:
package gzy.secret;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String token = Config.getCachedTOken(this);
if (token != null) {
Intent i = new Intent(this, AtyTimeLine.class);
i.putExtra(Config.KEY_TOKEN, token);
startActivity(i);
}else{
startActivity(new Intent(this,AtyLogin.class));
}
}
}
//在主窗口也写了一些代码,我看的也不是很明白,能不能帮帮忙,解释解释!谢谢 import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String token = Config.getCachedTOken(this);
if (token != null) {
Intent i = new Intent(this, AtyTimeLine.class);
i.putExtra(Config.KEY_TOKEN, token);
startActivity(i);
}else{
startActivity(new Intent(this,AtyLogin.class));
}
}
}