非UI线程中显示Toast

一、在BroadcastReceiver中开启了一个ReceivePushTask,然后想弹出一个toast,虽然不报错,但是一直没有效果,最后尝试startactivity实现
<activity android:name=".TranslucentActivity"
            android:theme="@android:style/Theme.Translucent.NoTitleBar">
     <intent-filter>
                 <action android:name="com.android.mms.SHOW_TOAST" />
                 <category android:name="android.intent.category.DEFAULT" />   
            </intent-filter>  
 </activity>


 

Intent messageIntent = new Intent("com.android.mms.SHOW_TOAST");// 必须加
messageIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);//必须加,不能用setclass
messageIntent.putExtra("content",report);
mContext.startActivity(messageIntent);

 

package com.android.mms;

import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;
import com.android.mms.R;
public class TranslucentActivity extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
 // TODO Auto-generated method stub
 super.onCreate(savedInstanceState);
 String str = getIntent().getStringExtra("content");
 if(str == null) {
  str = "A toast content!";
 }
 Toast.makeText(getApplicationContext(), str, Toast.LENGTH_LONG).show();
 finish();
}
}

 

你可能感兴趣的:(android)