Tôi đang cố bắt đầu một dịch vụ từ một dịch vụ khác. Nhưng tự hỏi có gì sai. Mã này cũng giống nhưBắt đầu dịch vụ từ một dịch vụ khác
class Service1 extends GCMBaseIntentService {
@Override
protected void onMessage(Context arg0, Intent intent) {
Toast.makeText(getApplicationContext(), "Hello", Toast.LENGTH_LONG).show();
Intent service = new Intent(getApplicationContext(), Service2.class);
startService(service);
}
}
Và Service2 là
class Service2 extends Service {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Service Started", Toast.LENGTH_LONG).show();
}
}
Tôi nhận được Toast "Hello" trong Service1 nhưng không Toast bị "Dịch vụ đầu" từ Service2
Hãy thử 'Service1.this' hoặc' getBaseContext() 'thay vì' getApplicationContext() 'để bắt đầu Service1 – Apurva
Bạn có gặp phải lỗi nào không? – Keshav1234
Tôi đã thử nhiều khả năng bao gồm điều này nhưng không có gì đã làm việc –