android.app.Activity.runOnUiThread()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(7.9k)|赞(0)|评价(0)|浏览(316)

本文整理了Java中android.app.Activity.runOnUiThread()方法的一些代码示例,展示了Activity.runOnUiThread()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Activity.runOnUiThread()方法的具体详情如下:
包路径:android.app.Activity
类名称:Activity
方法名:runOnUiThread

Activity.runOnUiThread介绍

暂无

代码示例

代码示例来源:origin: xfumihiro/ViewInspector

@Override public void onProfileDone() {
 ((Activity) mContext).runOnUiThread(new Runnable() {
  @Override public void run() {
   new ProfileResultDialog(
     new ContextThemeWrapper(mContext, BaseDialog.getDialogTheme(mContext)),
     profileProgressbar.getSamples()).show();
   closeProgressbar();
  }
 });
}

代码示例来源:origin: xfumihiro/ViewInspector

@Override public void onProgress(final int step) {
 ((Activity) mContext).runOnUiThread(new Runnable() {
  @Override public void run() {
   profileProgressbar.setProgress(step);
  }
 });
}

代码示例来源:origin: k9mail/k-9

public void setAlias(String alias) {
  // Note: KeyChainAliasCallback gives back "" on cancel
  if (alias != null && alias.equals("")) {
    alias = null;
  }
  mAlias = alias;
  // Note: KeyChainAliasCallback is a different thread than the UI
  mActivity.runOnUiThread(new Runnable() {
    @Override
    public void run() {
      updateView();
      if (mListener != null) {
        mListener.onClientCertificateChanged(mAlias);
      }
    }
  });
}

代码示例来源:origin: android10/Android-CleanArchitecture

/**
 * Run the operation of loading a bitmap on the UI thread.
 *
 * @param bitmap The image to load.
 */
private void loadBitmap(final Bitmap bitmap) {
 ((Activity) getContext()).runOnUiThread(new Runnable() {
  @Override public void run() {
   AutoLoadImageView.this.setImageBitmap(bitmap);
  }
 });
}

代码示例来源:origin: android10/Android-CleanArchitecture

/**
 * Loads the image place holder if any has been assigned.
 */
private void loadImagePlaceHolder() {
 if (this.imagePlaceHolderResId != -1) {
  ((Activity) getContext()).runOnUiThread(new Runnable() {
   @Override public void run() {
    AutoLoadImageView.this.setImageResource(
      AutoLoadImageView.this.imagePlaceHolderResId);
   }
  });
 }
}

代码示例来源:origin: commonsguy/cw-omnibus

@Override
public void onError(final String message, Exception e) {
 Log.e(getClass().getSimpleName(), message, e);
 getActivity().runOnUiThread(new Runnable() {
  @Override
  public void run() {
   Toast
    .makeText(getActivity(), message, Toast.LENGTH_LONG)
    .show();
  }
 });
}

代码示例来源:origin: facebook/facebook-android-sdk

@Override
  public void run() {
    final FetchedAppSettings settings = FetchedAppSettingsManager.queryAppSettings(appId, false);
    getActivity().runOnUiThread(new Runnable() {
      @Override
      public void run() {
        showToolTipPerSettings(settings);
      }
    });
  }
});

代码示例来源:origin: TommyLemon/APIJSON

/** 隐藏加载进度
 */
public static void dismissProgressDialog(Activity context) {
  if(context == null || progressDialog == null || progressDialog.isShowing() == false){
    return;
  }
  context.runOnUiThread(new Runnable() {
    @Override
    public void run() {
      progressDialog.dismiss();
    }
  });
}
//显示与关闭进度弹窗方法>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

代码示例来源:origin: TommyLemon/Android-ZBLibrary

/** 隐藏加载进度
 */
public static void dismissProgressDialog(Activity context) {
  if(context == null || progressDialog == null || progressDialog.isShowing() == false){
    return;
  }
  context.runOnUiThread(new Runnable() {
    @Override
    public void run() {
      progressDialog.dismiss();
    }
  });
}
//显示与关闭进度弹窗方法>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

代码示例来源:origin: cSploit/android

@Override
public void onReceive(final Context context, final Intent intent) {
 if(context instanceof Activity) {
  ((Activity) context).runOnUiThread(new Runnable() {
   @Override
   public void run() {
    notifyIntent(context, intent);
   }
  });
 } else {
  notifyIntent(context, intent);
 }
}

代码示例来源:origin: RobotiumTech/robotium

/**
 * Sets the progress of a given {@link ProgressBar}. Examples are SeekBar and RatingBar.
 * @param progressBar the {@code ProgressBar}
 * @param progress the progress that the {@code ProgressBar} should be set to
 */
public void setProgressBar(final ProgressBar progressBar,final int progress) {
  if(progressBar != null){
    Activity activity = activityUtils.getCurrentActivity(false);
    if(activity != null){
      activity.runOnUiThread(new Runnable()
      {
        public void run()
        {
          try{
            progressBar.setProgress(progress);
          }catch (Exception ignored){}
        }
      });
    }
  }
}

代码示例来源:origin: googlesamples/android-Camera2Basic

/**
 * Shows a {@link Toast} on the UI thread.
 *
 * @param text The message to show
 */
private void showToast(final String text) {
  final Activity activity = getActivity();
  if (activity != null) {
    activity.runOnUiThread(new Runnable() {
      @Override
      public void run() {
        Toast.makeText(activity, text, Toast.LENGTH_SHORT).show();
      }
    });
  }
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

public void removeSplashScreen() {
  logger.log(Level.FINE, "Splash Screen Picture Resource ID: {0}", splashPicID);
  if (splashPicID != 0) {
    if (frameLayout != null) {
      if (splashImageView != null) {
        getActivity().runOnUiThread(new Runnable() {
          @Override
          public void run() {
            splashImageView.setVisibility(View.INVISIBLE);
            frameLayout.removeView(splashImageView);
          }
        });
      } else {
        logger.fine("splashImageView is null");
      }
    } else {
      logger.fine("frameLayout is null");
    }
  }
}

代码示例来源:origin: RobotiumTech/robotium

/**
 * Sets the date in a given {@link DatePicker}.
 *
 * @param datePicker the {@code DatePicker} object.
 * @param year the year e.g. 2011
 * @param monthOfYear the month which is starting from zero e.g. 03
 * @param dayOfMonth the day e.g. 10
 */
public void setDatePicker(final DatePicker datePicker, final int year, final int monthOfYear, final int dayOfMonth) {
  if(datePicker != null){
    Activity activity = activityUtils.getCurrentActivity(false);
    if(activity != null){
      activity.runOnUiThread(new Runnable()
      {
        public void run()
        {
          try{
            datePicker.updateDate(year, monthOfYear, dayOfMonth);
          }catch (Exception ignored){}
        }
      });
    }
  }
}

代码示例来源:origin: RobotiumTech/robotium

public void doScreenshot() {
  View v = getScreenshotView();
  if(v == null) keepRunning = false;
  String final_name = name+"_"+seqno;
  ScreenshotRunnable r = new ScreenshotRunnable(v, final_name, quality);
  Log.d(LOG_TAG, "taking screenshot "+final_name);
  Activity activity = activityUtils.getCurrentActivity(false);
  if(activity != null){
    activity.runOnUiThread(r);
  }
  else {
    instrumentation.runOnMainSync(r);
  }
}

代码示例来源:origin: commonsguy/cw-omnibus

@Subscribe
public void onRandomEvent(final RandomEvent event) {
 if (getActivity() != null) {
  getActivity().runOnUiThread(new Runnable() {
   @Override
   public void run() {
    adapter.add(event);
   }
  });
 }
}

代码示例来源:origin: cSploit/android

@Override
public void onMenuClick(Activity activity, final MenuItem item) {
 if(isRunning()) {
  stop();
 } else {
  start();
 }
 activity.runOnUiThread(new Runnable() {
  @Override
  public void run() {
   buildMenuItem(item);
  }
 });
}

代码示例来源:origin: ACRA/acra

public void finishLastActivity(@Nullable Thread uncaughtExceptionThread) {
  // Trying to solve https://github.com/ACRA/acra/issues/42#issuecomment-12134144
  // Determine the current/last Activity that was started and close
  // it. Activity#finish (and maybe it's parent too).
  final Activity lastActivity = lastActivityManager.getLastActivity();
  if (lastActivity != null) {
    final boolean isMainThread = uncaughtExceptionThread == lastActivity.getMainLooper().getThread();
    if (ACRA.DEV_LOGGING) ACRA.log.d(LOG_TAG, "Finishing the last Activity prior to killing the Process");
    final Runnable finisher = () -> {
      lastActivity.finish();
      if (ACRA.DEV_LOGGING) ACRA.log.d(LOG_TAG, "Finished " + lastActivity.getClass());
    };
    if (isMainThread) {
      finisher.run();
    } else {
      lastActivity.runOnUiThread(finisher);
    }
    // A crashed activity won't continue its lifecycle. So we only wait if something else crashed
    if (!isMainThread) {
      lastActivityManager.waitForActivityStop(100);
    }
    lastActivityManager.clearLastActivity();
  }
}

代码示例来源:origin: robolectric/robolectric

@Test
public void shouldRunUiTasksImmediatelyByDefault() throws Exception {
 TestRunnable runnable = new TestRunnable();
 activity = Robolectric.setupActivity(DialogLifeCycleActivity.class);
 activity.runOnUiThread(runnable);
 assertTrue(runnable.wasRun);
}

代码示例来源:origin: robolectric/robolectric

@Test
public void shouldQueueUiTasksWhenUiThreadIsPaused() throws Exception {
 ShadowLooper.pauseMainLooper();
 activity = Robolectric.setupActivity(DialogLifeCycleActivity.class);
 TestRunnable runnable = new TestRunnable();
 activity.runOnUiThread(runnable);
 assertFalse(runnable.wasRun);
 ShadowLooper.unPauseMainLooper();
 assertTrue(runnable.wasRun);
}

相关文章

微信公众号

最新文章

更多

Activity类方法