Android BroadcastReceiver onReceive在MainActivity中更新TextView

Android BroadcastReceiver onReceive在MainActivity中更新TextView,第1张

Android BroadcastReceiver onReceive在MainActivity中更新TextView

在您的

MainActivity
初始化
MainActivity
变量如下。

public class MainActivity extends Activity {    private static MainActivity ins;    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        ins = this;         }    public static MainActivity  getInstace(){        return ins;    }    public void updateTheTextView(final String t) {        MainActivity.this.runonUiThread(new Runnable() { public void run() {     TextView textV1 = (TextView) findViewById(R.id.textV1);     textV1.setText(t); }        });    }}public class NotifAlarm extends BroadcastReceiver {    @Override    public void onReceive(Context context, Intent intent) {        try { MainActivity  .getInstace().updateTheTextView("String");        } catch (Exception e) {        }    }}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5499529.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-12
下一篇 2022-12-12

发表评论

登录后才能评论

评论列表(0条)

保存