因为新activity加载要有很多数据,就弄了个loadingactivity,但是为什么跳转的时候,原来的activity总闪一下,才会转到新的activity?
下面是loading的源码。
package com.xhw.conference;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
public class LoadingActivity extends Activity {
public static Class> context;
private ProgressDialog dialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
//设置一个progressdialog的弹窗
dialog = ProgressDialog.show(this, "please wait...", "getting data...");
Thread thread = new Thread(new Runnable() {
public void run() {
//do...
Message message = new Message();
message.what = 0;
mHandler.sendMessage(message);
}
});
thread.start();
}
//处理跳转到主Activity
private Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
Log.d(">>>>>Mhandler", "start handleMessage");
Intent mIntent = new Intent();
mIntent.setClass(LoadingActivity.this, context);
startActivity(mIntent);
LoadingActivity.this.finish();
Log.d(">>>>>Mhandler", "LoadActivity close");
if (msg.what == 0) {
dialog.dismiss();
}
}
};
}