创建IntentService,不调用onHandleIntent()

时间:2018-11-03 15:34:10

标签: android service intentservice

为什么现在调用了我的onHandleIntent? 因此,如果我按服务扩展类,则它可以正常工作。我需要intentService,因为它具有非主线程功能方法。

我的清单文件:

<service
        android:name=".tools.NewsService"
        android:enabled="true"
        android:exported="false">
    </service>

startService(..);调用的服务

public class NewsService extends IntentService {

private NotificationManager notificationManager;
final String LOG_TAG = "myLogs";
private Handler mHandler = new Handler();
public static final int timeout = 86400000;  // 24 hours
private Timer mTimer = null;
String urlNews = AppParams.newsUrl;

public NewsService() {
    super("name");
}

public void onCreate() {
    super.onCreate();
    Log.d(LOG_TAG, "onCreate");
}

@Override
protected void onHandleIntent(@Nullable Intent intent) {
    Log.d(LOG_TAG, "onHandleIntent");
    if (mTimer != null)
        mTimer.cancel();
    else
        mTimer = new Timer();   //recreate new
    mTimer.scheduleAtFixedRate(new TimeDisplay(), 0, 10*1000);
}

@Override
public void onStart(@Nullable Intent intent, int startId) {
    super.onStart(intent, startId);
    Log.d(LOG_TAG, "onStart");
}

public void onDestroy() {
    super.onDestroy();
    mTimer.cancel();
    Log.d(LOG_TAG, "onDestroy");
}

0 个答案:

没有答案