Hãy xem xét mã sau đây. Trong phương pháp Service.onStart()
tôi đã tạo và bắt đầu một chuỗi sẽ hiển thị thông báo Bánh mì nướng nhưng nó không hoạt động!Cách hiển thị thông báo bánh mì nướng từ chủ đề nền
public class MyService extends Service{
private static final String TAG = "MyService";
@Override
public IBinder onBind(Intent intent)
{
return null;
}
@Override
public void onCreate()
{
Toast.makeText(this, "My Service Created", Toast.LENGTH_SHORT).show();
}
@Override
public void onDestroy()
{
Toast.makeText(this, "My Service Stopped", Toast.LENGTH_SHORT).show();
}
@Override
public void onStart(Intent intent, int startid)
{
Toast.makeText(this, "My Service Started", Toast.LENGTH_SHORT).show();
DBIteratorThread dbThread=new DBIteratorThread();
dbThread.myService=this;
Thread t1 = new Thread(dbThread);
t1.start();
}
}
class DBIteratorThread implements Runnable
{
MyService myService;
public void run()
{
// Toast.makeText(myService, "Thread is Running", Toast.LENGTH_SHORT).show();
}
}
này nên làm việc cho bạn cũng http: // stackoverflow. com/questions/6134013/android-how-can-i-show-a-bánh mì nướng-từ-một-thread-chạy-trong-một-dịch vụ từ xa – eyespyus