Android在所有代码中使用Toast,包括非UI线程

来源:互联网 发布:vue.js prop 编辑:程序博客网 时间:2024/06/07 03:15
<application        android:name="base.Global"        android:allowBackup="true"        android:hardwareAccelerated="true"        android:icon="@drawable/ic_launcher"        android:label="@string/app_name"        android:persistent="true"        android:theme="@style/AppTheme" >.............</application>
package base;import android.app.Application;import android.content.Context;import android.os.Handler;import android.os.Message;import android.widget.Toast;import core.CCore;public class Global extends Application {public static Context context = null;public static Handler handler = null;// public CCore cr = // public static Activity mainActivity = null;public static CCore cr = null;// public static DeviceFragment deviceFragment = null;@Overridepublic void onCreate() {context = getApplicationContext();handler = new Handler_Global();super.onCreate();}private static class Handler_Global extends Handler {@Overridepublic void dispatchMessage(Message msg) {switch (msg.what) {case 0:Toast.makeText(context, (String)msg.obj, Toast.LENGTH_SHORT).show();break;default:break;}super.dispatchMessage(msg);}}}


0 0
原创粉丝点击