List of usage examples for android.os Looper myLooper
public static @Nullable Looper myLooper()
From source file:com.rener.sea.DBHelper.java
public void loginAuthentication(String username, String password) { if (Looper.myLooper() == null) Looper.prepare();/*w w w .j a va 2s. c o m*/ new ServerCalls().execute("LOGIN", username, password); // final String device_id = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID); // // Log.i(this.toString(), "HTTP Login call"); // // AsyncHttpClient client = new AsyncHttpClient(); // RequestParams params = new RequestParams(); // // params.put(DBSchema.AUTH_USER, username); // params.put(DBSchema.AUTH_PASS, password); // params.put(DBSchema.AUTH_DEVICE, device_id); // // client.post(DBSchema.AUTH_URL, params, new JsonHttpResponseHandler() { // @Override // public void onSuccess(int statusCode, Header[] headers, JSONObject response) { // // Log.i(this.toString(), "HTTP Sync success : i = " + statusCode + ", Header = " + headers.toString() + ", JSONObject = " + response.toString()); // //'device' => 0, 'user' => 0, 'hash' => 0, 'id' => $device, 'seq' => -1 // try { // boolean device = response.getBoolean("device"); // boolean user = response.getBoolean("user"); // boolean switchUser = response.getBoolean("flag"); // String hash = response.getString("hash"); // String deviceID = response.getString("id"); // long seq = response.getLong("seq"); // // if (device_id.equals(deviceID) && device && user) { // the responce come fro the server, user and passw corect // SharedPreferences sharedPref = context.getSharedPreferences( // context.getString(R.string.preference_file_key), Context.MODE_PRIVATE); // SharedPreferences.Editor editor = sharedPref.edit(); // editor.putString(context.getString(R.string.key_saved_passhash), hash); // editor.apply(); // // sync db // if (switchUser) { //// syncDB(); //// syncDBFull(); // Intent intent = new Intent(); // intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); // intent.setAction("AUTH"); // intent.putExtra("AUTH_RESULT", DBSchema.LOGIN_SUCCESS_NEW_USER); // context.sendBroadcast(intent); // // } else { // Intent intent = new Intent(); // intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); // intent.setAction("AUTH"); // intent.putExtra("AUTH_RESULT", DBSchema.LOGIN_SUCCESS); // context.sendBroadcast(intent); // } // // } // if (device_id.equals(deviceID) && device && !user) { // the response come fro the server, the device exist but wrong credentials // // Intent intent = new Intent(); // intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); // intent.setAction("AUTH"); // intent.putExtra("AUTH_RESULT", DBSchema.LOGIN_FAIL); // context.sendBroadcast(intent); // // } else if (!device) { // new device // getDummy(); // setSequence(seq); // if (user) { // user credentials are ok // SharedPreferences sharedPref = context.getSharedPreferences( // context.getString(R.string.preference_file_key), Context.MODE_PRIVATE); // SharedPreferences.Editor editor = sharedPref.edit(); // editor.putString(context.getString(R.string.key_saved_passhash), hash); // editor.apply(); // Intent intent = new Intent(); // intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); // intent.setAction("AUTH"); // intent.putExtra("AUTH_RESULT", DBSchema.LOGIN_SUCCESS_NEW_USER); // context.sendBroadcast(intent); //// syncDBFull(); // // } else { // user credentials are wrong // Intent intent = new Intent(); // intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); // intent.setAction("AUTH"); // intent.putExtra("AUTH_RESULT", DBSchema.LOGIN_FAIL); // context.sendBroadcast(intent); // } // } else { // Intent intent = new Intent(); // intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); // intent.setAction("AUTH"); // intent.putExtra("AUTH_RESULT", DBSchema.STATUS_ERROR); // context.sendBroadcast(intent); // } // // // } catch (JSONException e) { // e.printStackTrace(); // } // //// Intent intent = new Intent(); //// intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); //// intent.setAction("SYNC"); //// intent.putExtra("SYNC_RESULT", 200); //// context.sendBroadcast(intent); // // } // // @Override // public void onSuccess(int statusCode, Header[] headers, JSONArray response) { // Log.i(this.toString(), "HTTP Sync success : i = " + statusCode + ", Header = " + headers.toString() + ", JSONArray = " + response.toString()); // // } // // @Override // public void onFailure(int statusCode, Header[] headers, String response, Throwable error) { // Log.i(this.toString(), "HTTP Sync failure : statusCode = " + statusCode + ", Header = " + headers.toString() + ", response = " + response); // switch (statusCode) { // case 404: // Intent intent404 = new Intent(); // intent404.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); // intent404.setAction("AUTH"); // intent404.putExtra("AUTH_RESULT", 404); // context.sendBroadcast(intent404); // Toast.makeText(context, "Requested resource not found", Toast.LENGTH_LONG).show();// resource Not Found // break; // case 500: // Intent intent500 = new Intent(); // intent500.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); // intent500.setAction("AUTH"); // intent500.putExtra("AUTH_RESULT", 500); // context.sendBroadcast(intent500); // Toast.makeText(context, "Internal server error", Toast.LENGTH_LONG).show();// Internal Server Error // break; // default: // Intent intent = new Intent(); // intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); // intent.setAction("AUTH"); // intent.putExtra("AUTH_RESULT", DBSchema.STATUS_ERROR); // context.sendBroadcast(intent); // Toast.makeText(context, "NPI", Toast.LENGTH_LONG).show();// no se que paso // break; // // // } // } // // // }); }
From source file:android.app.Activity.java
/** * Cause this Activity to be recreated with a new instance. This results * in essentially the same flow as when the Activity is created due to * a configuration change -- the current instance will go through its * lifecycle to {@link #onDestroy} and a new instance then created after it. *//* w ww . j ava 2s. co m*/ public void recreate() { if (mParent != null) { throw new IllegalStateException("Can only be called on top-level activity"); } if (Looper.myLooper() != mMainThread.getLooper()) { throw new IllegalStateException("Must be called from main thread"); } mMainThread.requestRelaunchActivity(mToken, null, null, 0, false, null, false); }