java Android会话管理不工作
我正在尝试用Android管理会话。我使用共享首选项来存储用户数据。当任何用户完全登录并且我的应用程序的主页现在应该打开时,问题就会出现,但是Logcat显示错误,即没有活动来处理此页面
这是登录的代码。爪哇
public class Login extends Activity {
Button but;
TextView tex,tex2;
EditText nameEdit,passEdit;
public static final String MyPREFERENCES = "MyPrefs" ;
public static final String name = "nameKey";
public static final String pass = "passwordKey";
SharedPreferences sharedpreferences;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
but=(Button)findViewById(R.id.login);
// nameEdit, passEdit get the user entered username and password respectively.
nameEdit = (EditText)findViewById(R.id.editText1);
passEdit = (EditText)findViewById(R.id.editText2);
but.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
//storing userdetails in Shared Preference
Editor editor = sharedpreferences.edit();
String u = nameEdit.getText().toString();
String p = passEdit.getText().toString();
editor.putString(name, u);
editor.putString(pass, p);
editor.commit();
Intent openStartingPoint=new Intent("app.something.com.Menu");
startActivity(openStartingPoint); //here occurs the error no activity found to handle this
finish();
return;
}
});
}
@Override
protected void onResume() {
//if user already logged in then direct him to "Menu".
sharedpreferences=getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);
if (sharedpreferences.contains(name))
{
if(sharedpreferences.contains(pass)){
Intent i = new Intent("app.something.com.Menu");
startActivity(i);
}
}
super.onResume();
}
}
注销用户的方法如下:清除共享首选项编辑器
public void logout()
{
SharedPreferences sharedpreferences = getSharedPreferences(Login.MyPREFERENCES,Context.MODE_PRIVATE);
Editor editor = sharedpreferences.edit();
editor.clear();
editor.commit();
moveTaskToBack(true);
Control_panel.this.finish();
return;
}
这是舱单代码:
<activity
安卓:screenOrientation="portrait"
安卓:name="app.something.com.Login"
安卓:label="@string/app_name" >
<intent-filter>
<action 安卓:name="安卓.intent.action.MAIN" />
<category 安卓:name="安卓.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
安卓:name="app.something.com.Menu"
安卓:label="@string/app_name" >
<intent-filter>
<action 安卓:name="app.something.com.Menu" />
<category 安卓:name="安卓.intent.category.DEFAULT" />
</intent-filter>
</activity>
我不知道为什么即使在“文件”菜单中也会出现ActivityNotFoundException。java扩展了Activity类,清单中也提到了它。在这个运行时异常之后,当我再次启动我的应用程序时,我将直接进入对应于菜单的活动。java,这正是应该发生的事情。但只有当有人试图登录时,才会出现异常
请帮帮我
提前感谢:)
# 1 楼答案
打开/启动另一个活动的意图如下
所以,我不认为你写的是正确的