如何在服务中展示烤面包?

时间:2020-03-03 09:44:12

标签: java android kotlin toast android-jetpack

我是android的新手。我无法显示toast。

val configBuilder = FirebaseRemoteConfigSettings.Builder()
            if (BuildConfig.DEBUG) {
                val cacheInterval: Long = 0
                configBuilder.setMinimumFetchIntervalInSeconds(cacheInterval)
            }

1 个答案:

答案 0 :(得分:1)

使用这样的代码

public class MyService extends Service {

    String msg="Toast message show";

    Thread t = new Thread(){
        public void run(){

            Message myMessage=new Message();
            Bundle resBundle = new Bundle();
            resBundle.putString("status", "SUCCESS");
            myMessage.obj=resBundle;
            handler.sendMessage(myMessage);
        }
    };

}

private Handler handler = new Handler() {
    @Override
    public void handleMessage(Message msg) {
        Toast.makeText(getApplicationContext(), "msg", Toast.LENGTH_LONG).show();
    }
}