Android Service to show toast

后端 未结 3 1170
-上瘾入骨i
-上瘾入骨i 2020-12-09 00:55

This code is supposed to use a service to show a toast message. There are no errors, but it doesn\'t show the toast.

main activity

public class Main         


        
3条回答
  •  北荒
    北荒 (楼主)
    2020-12-09 01:55

    Try this:

    Handler handler = new Handler(Looper.getMainLooper());
    handler.post(new Runnable() {
    
        @Override
        public void run() {
                Toast.makeText(YourService.this.getApplicationContext(),"My Awesome service toast...",Toast.LENGTH_SHORT).show();
                }
            });
    

提交回复
热议问题