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

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

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

Activity.getMainLooper介绍

暂无

代码示例

代码示例来源: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: com.uphyca/android-junit4-robolectric

/**
 * @return
 * @see android.content.ContextWrapper#getMainLooper()
 */
public Looper getMainLooper() {
  return mActivity.getMainLooper();
}

代码示例来源:origin: ckcz123/PKUHelper-Android

public ImageDownload(Activity _activity, ImageView imageView,
           String url) {
  activity = _activity;
  eventHandler = new EventHandler(activity.getMainLooper());
  imageViews.add(imageView);
  urls.add(url);
}

代码示例来源:origin: ckcz123/PKUHelper-Android

public ImageDownload(Activity _activity, ArrayList<ImageView> _imageViews,
           ArrayList<String> _urls) {
  activity = _activity;
  imageViews = new ArrayList<ImageView>(_imageViews);
  urls = new ArrayList<String>(_urls);
  eventHandler = new EventHandler(activity.getMainLooper());
}

代码示例来源:origin: hejunlin2013/TVSample

public static void asyncGet(Request request, final Activity activity, final Callback callback) {
  Log.d(REQUEST_TAG, "async request Url: " + request.toString());
  AppManager.getHttpClient().newCall(request).enqueue(new Callback() {
    Handler mainHandler = new Handler(activity.getMainLooper());
    @Override
    public void onFailure(final Call call, final IOException e) {
      mainHandler.post(new Runnable() {
        @Override
        public void run() {
          callback.onFailure(call, e);
        }
      });
    }
    @Override
    public void onResponse(final Call call, final Response response) throws IOException {
      mainHandler.post(new Runnable() {
        @Override
        public void run() {
          try {
            callback.onResponse(call, response);
          } catch (IOException e) {
            e.printStackTrace();
          }
        }
      });
    }
  });
}

代码示例来源:origin: marzika/Snapprefs

v.setOrientation(LinearLayout.VERTICAL);
v.setLayoutParams(linearparams);
final Handler handler = new Handler(HookMethods.SnapContext.getMainLooper());

代码示例来源:origin: fire3/sailorcast

public static void asyncGet(Request request, final Activity activity, final Callback callback) {
  Log.d("fire3", "async request Url: " + request.urlString());
  SailorCast.getHttpClient().newCall(request).enqueue(new Callback() {
    Handler mainHandler = new Handler(activity.getMainLooper());
    @Override
    public void onFailure(final Request request, final IOException e) {
      mainHandler.post(new Runnable() {
        @Override
        public void run() {
          callback.onFailure(request,e);
        }
      });
    }
    @Override
    public void onResponse(final Response response) throws IOException {
      mainHandler.post(new Runnable() {
        @Override
        public void run() {
          try {
            callback.onResponse(response);
          } catch (IOException e) {
            e.printStackTrace();
          }
        }
      });
    }
  });
}

代码示例来源:origin: linkedin/shaky-android

@Before
public void setUp() {
  delegate = mock(ShakeDelegate.class);
  activity = mock(Activity.class);
  fragmentManager = mock(FragmentManager.class);
  when(activity.getFragmentManager()).thenReturn(fragmentManager);
  when(activity.getApplicationContext()).thenReturn(activity);
  when(activity.getMainLooper()).thenReturn(Looper.getMainLooper());
  when(delegate.getSensitivityLevel()).thenReturn(ShakeDelegate.SENSITIVITY_LIGHT);
  shaky = new Shaky(activity, delegate);
  shaky.setActivity(activity);
}

代码示例来源:origin: PuffOpenSource/Puff-Android

public AppCompatDialog showProgressbar(Activity activity, long timeout, boolean cancelable) {
  final AppCompatDialog dialog = new AppCompatDialog(activity);
  dialog.setContentView(R.layout.dialog_progress);
  dialog.setCancelable(cancelable);
  dialog.setTitle("Progressing...");
  ProgressBar progressBar = (ProgressBar) dialog.findViewById(R.id.progress);
  if (timeout > 0) {
    Handler handler = new Handler(activity.getMainLooper());
    handler.postDelayed(new Runnable() {
      @Override
      public void run() {
        dialog.cancel();
        dialog.dismiss();
      }
    }, timeout);
    dialog.show();
  } else {
    dialog.show();
  }
  return dialog;
}

代码示例来源:origin: DF1E/SimpleExplorer

@Override
public void onActivityCreated(Bundle state) {
  super.onActivityCreated(state);
  mActivity = getActivity();
  Intent intent = mActivity.getIntent();
  fm = getFragmentManager();
  mObserverCache = FileObserverCache.getInstance();
  mUpdatePathListener = (onUpdatePathListener) mActivity;
  mActionController = new ActionModeController(mActivity);
  mActionController.setListView(mListView);
  if (sHandler == null) {
    sHandler = new Handler(mActivity.getMainLooper());
  }
  initDirectory(state, intent);
}

相关文章

微信公众号

最新文章

更多

Activity类方法