Android的:如何保持上后退按钮会话?按钮、Android

2023-09-07 13:32:05 作者:差點心動了

我的应用程序包含两个活动课。从第一个活动的用户可以登录并从第二个活动用户还可以查看与注销按钮他们的项目details.I'm维护会话。在我的应用程序,如果用户在后退按钮按下,从第二个活动,然后它去Apps部分(指主菜单),并在一段时间的用户在我的应用程序图标,点击后进入的第一项活动没有第二个活动用户还没有注销。 我想用户应该去次活动不是第一个活动,如果用户已经登录。我曾经试过,但没有工作,还是我想。 我怎样才能做到以上的东西请任何人建议我的答案。

My App contains two Activity Classes. from first activity user can login and from second activity user can view their project details.I'm maintaining session also with logout button. In my app if user clicked on back button from second activity then it goes to apps section(means main menu) and after some time user clicked on my app icon it goes to first activity not second activity yet user didn't logout. I want user should go to second activity not first activity if user already login. I had tried but not working and still I am trying. How can i do the above stuff please anybody suggest me the answer.

推荐答案

您不必显示的第一项活动。但实际上总有主要活动。这应该决定是否直接登录活动启动,或者直接显示用户的内容。可以只要你开始登录或内容使用活动主要活动结束(),所以当用户推回(),他将不会再看到主要活动。

You do not have to display first activity. But in fact there is always main activity. That should decide whether to start directly login activity, or to display user content directly. You can use finish() from main activity as soon as you started login or content activity, so when user pushes back(), he will not see main activity again.

MainActivity extends Activity
{
 public void onCreate()
 {
   if isLogged()
     startActivity(new Intent(ContentActivity ...));
   else
     startActivity(new Intent(LoginActivity...));
   finish()
}

LoginActivity extends Activity
{
  ...
  public void onLoginSuccess(String username)
  {
     // called from dialog OK button and login process success
     startActivity(new Intent(ContentActivity ...));
     finish();
  }
}