码迷,mamicode.com
首页 > 其他好文 > 详细

Activity UI Handler ProgressBar AsyncTask

时间:2016-02-29 19:32:17      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:

package io.vov.vitamio.activity;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.Window;
import io.vov.vitamio.Vitamio;
import java.lang.ref.WeakReference;

public class InitActivity extends Activity
{
  public static final String FROM_ME = "fromVitamioInitActivity";
  private ProgressDialog mPD;
  private UIHandler uiHandler;

  protected void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    getWindow().addFlags(128);
    this.uiHandler = new UIHandler(this);
    new AsyncTask()
    {
      protected Boolean doInBackground(Object[] paramArrayOfObject)
      {
        return Boolean.valueOf(Vitamio.initialize(InitActivity.this, InitActivity.this.getResources().getIdentifier("libarm", "raw", InitActivity.this.getPackageName())));
      }

      protected void onPostExecute(Boolean paramBoolean)
      {
        if (paramBoolean.booleanValue())
          InitActivity.this.uiHandler.sendEmptyMessage(0);
      }

      protected void onPreExecute()
      {
        InitActivity.this.mPD = new ProgressDialog(InitActivity.this);
        InitActivity.this.mPD.setCancelable(false);
        InitActivity.this.mPD.setMessage(InitActivity.this.getString(InitActivity.this.getResources().getIdentifier("vitamio_init_decoders", "string", InitActivity.this.getPackageName())));
        InitActivity.this.mPD.show();
      }
    }
    .execute(new Object[0]);
  }

  private static class UIHandler extends Handler
  {
    private WeakReference<Context> mContext;

    public UIHandler(Context paramContext)
    {
      this.mContext = new WeakReference(paramContext);
    }

    public void handleMessage(Message paramMessage)
    {
      InitActivity localInitActivity = (InitActivity)this.mContext.get();
      switch (paramMessage.what)
      {
      default:
        return;
      case 0:
      }
      localInitActivity.mPD.dismiss();
      Intent localIntent1 = localInitActivity.getIntent();
      Intent localIntent2 = new Intent();
      localIntent2.setClassName(localIntent1.getStringExtra("package"), localIntent1.getStringExtra("className"));
      localIntent2.setData(localIntent1.getData());
      localIntent2.putExtras(localIntent1);
      localIntent2.putExtra("fromVitamioInitActivity", true);
      localInitActivity.startActivity(localIntent2);
      localInitActivity.finish();
    }
  }
}

 

Activity UI Handler ProgressBar AsyncTask

标签:

原文地址:http://www.cnblogs.com/qianyukun/p/5228341.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!