Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Splash pages are not recommended according to the Android Design Guidelines: <a href="http://developer.android.com/design/patterns/help.html" rel="nofollow">http://developer.android.com/design/patterns/help.html</a>. Why do you want to make a user wait 5 seconds to access your app?</p> <p>I have commented your code with my feedback/answers.</p> <p>Just use SharedPreferences. That is the easiest way:</p> <pre><code>public class SplashScreen extends Activity { private long splashDelay = 5000; //5 seconds private Activity splashScreen; private Intent intent; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.splash_screen); splashScreen = this; // get your shared preferences stored in your app. If the username has been // set then this user has already logged in SharedPreferences prefs = getSharedPreferences("name_for_file", 0); // return the username of null if none exists String username = prefs.getString("username", null); // if user has already logged in, just go to MainActivity if (username == null) { intent = new Intent(this, LoginActivity.class); } else { intent = new Intent(this, MainActivity.class); } TimerTask task = new TimerTask() { @Override public void run() { //finish(); &lt;- you don't need to call finish, the OS takes care of that splashScreen.startActivity(intent); } }; Timer timer = new Timer(); timer.schedule(task, splashDelay); } } public class LoginActivity extends Activity { Intent i; Button signin, signup; CheckBox check; String name = "", pass = ""; byte[] data; HttpPost httppost; StringBuffer buffer; HttpResponse response; HttpClient httpclient; InputStream inputStream; SharedPreferences app_preferences; List&lt;NameValuePair&gt; nameValuePairs; EditText editTextId, editTextP; Activity loginActivity; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.login); loginActivity = this; signin = (Button) findViewById(R.id.signin); signup = (Button) findViewById(R.id.signup); editTextId = (EditText) findViewById(R.id.editTextId); editTextP = (EditText) findViewById(R.id.editTextP); // app_preferences = PreferenceManager.getDefaultSharedPreferences(this); app_preferences = getSharedPreferences("name_of_file", 0); check = (CheckBox) findViewById(R.id.check); // if they got to this activity they are not logged in, so why are you // checking here? // the common pattern is to use null // String Str_user = app_preferences.getString("username", null); // String Str_pass = app_preferences.getString("password", null); // checked only has two states, use a boolean // boolean Str_check = app_preferences.getBoolean("checked", false); // if (Str_check)) { // editTextId.setText(Str_user); // editTextP.setText(Str_pass); // check.setChecked(true); // } signin.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { LoginTask login = new LoginTask(); login.execute(); } }); signup.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(this, SignUpActivity.class) startActivity(intent); } }); } // why are you sending them back to the splash? public void Move_to_next() { final Handler handle = new Handler(); Runnable delay = new Runnable() { public void run() { startActivity(new Intent(LoginActivity.this, SplashActivity.class)); finish(); } }; //why are you making people wait? handle.postDelayed(delay,2000); } // This is never being called public void Move_next() { startActivity(new Intent(LoginActivity.this, SignUpActivity.class)); //finish(); &lt;- the OS will do this } @SuppressLint("NewApi") private class LoginTask extends AsyncTask &lt;Void, Void, String&gt; { @SuppressLint("NewApi") @Override protected void onPreExecute() { super.onPreExecute(); // Show progress dialog here } // best practice for android is to use HttpUrlConnection: // http://android-developers.blogspot.com/2011/09/androids-http-clients.html // there is also AndroidHttpClient, which is the class google used in their // Google IO 2013 app. It is pretty clean. https://code.google.com/p/basic-http-client/ /* AndroidHttpClient httpClient = new AndroidHttpClient("http://www.google.com"); ParameterMap params = httpClient.newParams().add("q", "GOOG"); httpClient.setMaxRetries(3); httpClient.get("/finance", params, new AsyncCallback() { public void onComplete(HttpResponse httpResponse) { System.out.println(httpResponse.getBodyAsString()); } public void onError(Exception e) { e.printStackTrace(); } }); */ @Override protected String doInBackground(Void... arg0) { try { httpclient = new DefaultHttpClient(); httppost = new HttpPost("http://xxx/login1.php"); // Add your data nameValuePairs = new ArrayList&lt;NameValuePair&gt;(2); nameValuePairs.add(new BasicNameValuePair("UserEmail", name.trim())); nameValuePairs.add(new BasicNameValuePair("Password", pass.trim())); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); // Execute HTTP Post Request response = httpclient.execute(httppost); inputStream = response.getEntity().getContent(); data = new byte[256]; buffer = new StringBuffer(); int len = 0; while (-1 != (len = inputStream.read(data))) { buffer.append(new String(data, 0, len)); } inputStream.close(); return buffer.toString(); } catch (Exception e) { e.printStackTrace(); } return ""; } @SuppressLint("NewApi") @Override protected void onPostExecute(String result) { super.onPostExecute(result); // Hide progress dialog here if (buffer.charAt(0) == 'Y') { Toast.makeText(LoginActivity.this, "login successful", Toast.LENGTH_SHORT).show(); // don't send them back to the splash, they are logged in // save username and pass, and move forward SharedPreferences settings = loginActivity.getSharedPreferences("name_of_file", 0); SharedPreferences.Editor editor = settings.edit(); editor.putString("username", put whatever you get from server).commit(); editor.putString("password", put whatever you get from server).commit(); Intent intent = new Intent(loginActivity, WelcomeActivity.class); startActivity(intent); } else { Toast.makeText(LoginActivity.this, "Invalid Username or password", Toast.LENGTH_SHORT).show(); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload