2015-11-19 174 views
-2

我正在开发一个Android应用程序,我在启动屏幕上使用手机号注册。我想要的只是在安装应用程序时,注册应该只需要一次和第一次。安装应用程序后,应用程序应从另一个活动打开,而不是从启动屏幕打开。如何可能。如何从两个活动启动一个Android应用程序

+0

您需要添加SharedPrefrence“http://www.tutorialspoint.com/android/android_shared_preferences.htm”来存储所需的信息。当应用第二次打开时,您需要检查sharedPrefrence的值。 – Naitik

+0

此链接显示错误“找不到页面” –

+0

照片添加一些代码? –

回答

0

在splash类中,您应该检查应用程序是否第一次运行。如果是,继续,如果没有,则开始第二个活动。可以通过检查布尔值,将其存储在共享首选项中,并且每次在启动时检查其值。

0

尝试使用SharedPrefrence.But它不是完整的答案。显示您的SplashScreen检查您的用户是否注册。

 Boolean REG_RESPONCE = new Session_manag(getActivity()).IsSessionCheckOrCreated(); 
      if (REG_RESPONCE.equals(true)) { 
       Intent toHomeactivity = new Intent(Splash.this, MainMenu.class); 
       finish(); 
       startActivity(toHomeactivity); 
      } else { 

       Intent i = new Intent(Splash.this, SignUp.class); 
       finish(); 
       startActivity(i); 
      } 
0

这太容易处理。你需要的是一个如何实现这个概念。所以我给你的路线图,做一些在互联网上搜索我要告诉你的事情。这些步骤如下

  1. 我认为这样做的简单方法是实现共享首选项。共享喜好是什么?他们会将您的客户信息存储到应用程序中,例如他的姓名,密码
  2. 因此,当Spalsh首先检查共享首选项中是否有值时,如果有值,则表示您的用户已经登录
  3. 如果用户没有存储任何值,那么这意味着您需要将他带到注册活动。
  4. 所以用这种方式你可以把你的用户放在你想要的地方。但是没有办法同时使用两项活动。

您可以阅读herethis的共享偏好设置,这是一个不错的教程,帮助您入门。

4

成功注册登录后,您必须将数据存储在SharedPreferences中。

AppTypeDetails是SharedPreferences的类。

AppTypeDetails.getInstance(SignUpActivity.this).setEmail(<Your Email ID>); 
AppTypeDetails.getInstance(SignUpActivity.this).setPassword(<Your Password>); 

AppTypeDetails.java

import android.content.Context; 
import android.content.SharedPreferences; 
import android.preference.PreferenceManager; 

public class AppTypeDetails { 

    private SharedPreferences sh; 

    private AppTypeDetails() { 

    } 

    private AppTypeDetails(Context mContext) { 
     sh = PreferenceManager.getDefaultSharedPreferences(mContext); 
    } 

    private static AppTypeDetails instance = null; 

    /** 
    * 
    * @param mContext 
    * @return {@link AppTypeDetails} 
    */ 
    public synchronized static AppTypeDetails getInstance(Context mContext) { 
     if (instance == null) { 
      instance = new AppTypeDetails(mContext); 
     } 
     return instance; 
    } 

    // get username 
    public String getEmail() { 
     return sh.getString("email", ""); 
    } 

    public void setEmail(String email) { 
     sh.edit().putString("email", email).commit(); 
    } 

    // get password 
    public String getPassword() { 
     return sh.getString("password", ""); 
    } 

    public void setPassword(String password) { 
     sh.edit().putString("password", password).commit(); 
    } 

    public void clear() { 
     sh.edit().clear().commit(); 
    } 

} 

现在检查下面的代码在启动画面。

String email = AppTypeDetails.getInstance(SplashScreen.this).getEmail(); 
String pass = AppTypeDetails.getInstance(SplashScreen.this).getPassword(); 

if (email.trim().isEmpty() && pass.trim().isEmpty()) { 
    Intent intent = new Intent(SplashScreen.this, Login.class); 
    startActivity(intent); 
} else { 
    Intent intent = new Intent(SplashScreen.this, MainScreenTabHost.class); 
    startActivity(intent); 
} 

为了清楚SharedPreferences

呼叫上注销clear()方法。

+0

感谢您的指导 –

+0

@MMartin如果我的回答对你有帮助,那么接受我的回答。 –

0

您可以在启动屏幕上检查用户是否已用数字签名或不签名的条件,因为您必须在SharedPreferences中保存该数字。 按照thew下面的步骤,

第1步:当用户打开应用程序首次启动画面会come.here您可以检查条件number.At第一次,当用户来到在App值(数)不到风度的存在SharedPreferences.so应用程序将要求输入号码。当用户输入号码并提交时,将其存储在SharedPreferences中。

第二步:现在,第二次当用户进入启动画面时,由于SharedPreferences具有值(数字),所以该条件成为真。因此您可以在第二项活动上重定向应用。

相关问题