Android Open Source - RSSNewsReaderApp Update Service






From Project

Back to project page RSSNewsReaderApp.

License

The source code is released under:

GNU General Public License

If you think the Android project RSSNewsReaderApp listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.romanostrechlis.rssnews.auxiliary;
//w  w w  .ja v  a 2  s  .  com
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;

/**
 * Custom Service to handle the update process.
 * 
 * @author Romanos Trechlis
 *
 */
public class UpdateService extends Service {

  private static final String TAG = "UpdateService";
  private static UpdateService INSTANCE;
  private Thread thread;

  /**
   * This is necessary because we create a new thread each time onStartCommand is called 
   * and we need a method to control the creation of only one thread for updates.
   * 
   * @return true   if service is already running
   */
  public static Boolean isRunning() {
    if (INSTANCE == null) {
      return false;
    } else {
      return true;
    }
  }

  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
    INSTANCE = this;
    update();
    return Service.START_NOT_STICKY;
  }

  @Override
  public IBinder onBind(Intent intent) {
    // TODO Auto-generated method stub
    return null;
  }
  
  private void update() {
    // Log.d(TAG, "Service started: " + String.valueOf(Thread.activeCount()));
    final DatabaseHandler db = DatabaseHandler.getInstance(this);
    thread = new Thread() {
      @Override
      public void run() {
        super.run();
        android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_BACKGROUND);
        try {
          while(true) {
            Helper.downloadContent(db, getApplicationContext());
            // Log.d(TAG, String.valueOf(Thread.activeCount()));
            Thread.sleep(Helper.getUpdateInterval(getApplicationContext()));
          }
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
      }
    };
    thread.start();
  }

}




Java Source Code List

com.romanostrechlis.rssnews.DetailActivity.java
com.romanostrechlis.rssnews.MainActivity.java
com.romanostrechlis.rssnews.auxiliary.DatabaseHandler.java
com.romanostrechlis.rssnews.auxiliary.ExpCustomListAdapter.java
com.romanostrechlis.rssnews.auxiliary.Helper.java
com.romanostrechlis.rssnews.auxiliary.ManageCustomArrayAdapter.java
com.romanostrechlis.rssnews.auxiliary.OnSwipeTouchListener.java
com.romanostrechlis.rssnews.auxiliary.RetrieveFeedTask.java
com.romanostrechlis.rssnews.auxiliary.UpdateService.java
com.romanostrechlis.rssnews.content.RssFeed.java
com.romanostrechlis.rssnews.content.RssItem.java
com.romanostrechlis.rssnews.legacy.MainCustomArrayAdapter.java
com.romanostrechlis.rssnews.legacy.NodeDetailActivity.java
com.romanostrechlis.rssnews.legacy.NodeDetailFragment.java
com.romanostrechlis.rssnews.legacy.NodeListActivity.java
com.romanostrechlis.rssnews.legacy.NodeListFragment.java
com.romanostrechlis.rssnews.managefeeds.EditRssFeedActivity.java
com.romanostrechlis.rssnews.managefeeds.ManageActivity.java
com.romanostrechlis.rssnews.managefeeds.NewFeedsActivity.java
com.romanostrechlis.rssnews.settings.SettingsActivity.java