private void sleep(int time) { try { Thread.sleep(time); } catch (InterruptedException e) { e.printStackTrace(); } }
public void onClickCreat(View view) { CurrencyAd ad = new CurrencyAd( editTextName.getText().toString(), editTextCurrency.getText().toString(), editTextCountSits.getText().toString(), null, editTextPrice.getText().toString(), user.getEmail(), editTextAbout.getText().toString(), editTextCityEnd.getText().toString(), editTextCityStart.getText().toString(), editTextDateEnd.getText().toString(), editTextDateStart.getText().toString(), editTextTimeEnd.getText().toString(), editTextTimeStart.getText().toString()); GsonBuilder builder1 = new GsonBuilder(); Gson gson1 = builder1.create(); String a = gson1.toJson(ad); try { sent = new CreatAdAsyncTask().execute(gson1.toJson(ad)).get(5, TimeUnit.SECONDS); startActivity(new Intent(this, MainActivity.class)); Toast.makeText(this, "Ваша заявка создана!", Toast.LENGTH_LONG).show(); } catch (InterruptedException e) { Logger.getAnonymousLogger().warning(e.getMessage()); } catch (ExecutionException e) { Logger.getAnonymousLogger().warning(e.getMessage()); } catch (TimeoutException e) { Toast.makeText(this, "Oooops!", Toast.LENGTH_SHORT).show(); } }
private void downloadImageThread() { Thread thread = new Thread(null, runInBackground, "Background"); thread.start(); try { thread.join(); } catch (InterruptedException e) { e.printStackTrace(); } }
@Override protected Void doInBackground(Integer... params) { // try { Thread.sleep(params[0]); } catch (InterruptedException e) { // e.printStackTrace(); } return null; }
/** 线程运行的方法,当线程start后执行 */ @Override public void run() { while (flag) { mDraw(); // 调用自定义的绘图方法 mGameLogic(); // 调用自定义的逻辑方法 try { Thread.sleep(50); // 让线程休息50毫秒 } catch (InterruptedException e) { e.printStackTrace(); } } }
private boolean ExecutiveExists(String executive) { boolean fExists = false; try { Process process = Runtime.getRuntime().exec(executive); int exitCode = process.waitFor(); fExists = exitCode != 127; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } return fExists; }
@SuppressWarnings("unused") @Override public void onDestroy() { super.onDestroy(); // Stop the Bluetooth chat services if (D) Log.e(TAG, "--- ON DESTROY ---"); if (false) { RunDisConnectionInThread(); try { Thread.sleep(2000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } mStatusTimer.cancel(); finish(); }
@Override protected String doInBackground(String... arg0) { // TODO Auto-generated method stub String data = null; FileInputStream fis = null; for (int i = 0; i < 25; i++) { // referencing progressupdate method publishProgress(4); try { Thread.sleep(100); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } dial.dismiss(); try { fis = openFileInput(FILENAME); byte[] arr = new byte[fis.available()]; // getting number of bytes in fis while (fis.read(arr) != -1) ; // reading the bytes in fis { data = new String(arr); } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { try { fis.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return data; }