tôi đang theo hướng dẫn để setup a service to start on boot nơi những mảnh cuối cùng của mã này là:Tôi có cần thêm bộ lọc ý định khi bắt đầu dịch vụ không?
Hãy một mục dịch vụ này trong AndroidManifest.xml như
<service android:name="MyService">
<intent-filter>
<action
android:name="com.wissen.startatboot.MyService" />
</intent-filter>
</service>
Bây giờ bắt đầu dịch vụ này trong phương pháp onReceive các BroadcastReceiver MyStartupIntentReceiver của như
public void onReceive(Context context, Intent intent) {
Intent serviceIntent = new Intent();
serviceIntent.setAction("com.wissen.startatboot.MyService");
context.startService(serviceIntent);
}
Như bạn thấy nó sử dụng bộ lọc ý định và khi bắt đầu dịch vụ thêm hành động. Tôi có thể chỉ sử dụng
startService(new Intent(this, MyService.class));
Ưu điểm của cái nào so với loại kia?