我想从 asytask 向我的主要活动发送一些消息。我想用消息对象(处理程序)来做到这一点。在我的主要活动中,我创建了这个
final Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
msg.toString();
}
};
我传递给 asytask 的对象
new splash(first.this,mHandler).execute();
以及从此方法向活动发送消息的 asytask
protected void onPostExecute(String result) {
Message msg = new Message();
Bundle bundle = new Bundle();
bundle.putString("ActivityName",this.newActivity);
msg.setData(bundle);
mHandler.sendMessage(msg);
Dialog.dismiss();
日志猫
09-29 11:55:41.631: E/AndroidRuntime(473): FATAL EXCEPTION: main
09-29 11:55:41.631: E/AndroidRuntime(473): java.lang.NullPointerException
09-29 11:55:41.631: E/AndroidRuntime(473): at tools.splash.onPostExecute(splash.java:109)
09-29 11:55:41.631: E/AndroidRuntime(473): at tools.splash.onPostExecute(splash.java:1)
09-29 11:55:41.631: E/AndroidRuntime(473): at android.os.AsyncTask.finish(AsyncTask.java:417)
09-29 11:55:41.631: E/AndroidRuntime(473): at android.os.AsyncTask.access$300(AsyncTask.java:127)
09-29 11:55:41.631: E/AndroidRuntime(473): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
09-29 11:55:41.631: E/AndroidRuntime(473): at android.os.Handler.dispatchMessage(Handler.java:99)
09-29 11:55:41.631: E/AndroidRuntime(473): at android.os.Looper.loop(Looper.java:123)
09-29 11:55:41.631: E/AndroidRuntime(473): at android.app.ActivityThread.main(ActivityThread.java:3683)
09-29 11:55:41.631: E/AndroidRuntime(473): at java.lang.reflect.Method.invokeNative(Native Method)
09-29 11:55:41.631: E/AndroidRuntime(473): at java.lang.reflect.Method.invoke(Method.java:507)
09-29 11:55:41.631: E/AndroidRuntime(473): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
09-29 11:55:41.631: E/AndroidRuntime(473): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
09-29 11:55:41.631: E/AndroidRuntime(473): at dalvik.system.NativeStart.main(Native Method)