Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>First of all I think you will call the Service class from an Activity class or from any BroadCastReceiver class. </p> <p>You would like to start the service after some specific or may be after 5000ms . Though your question is not clear for me. Still as per my knowledge you have to call the service from your service class. For example:</p> <pre><code> public class UpdateWidgetServiceDemo extends Service { public static int numberOfItems=0; String resultURL=""; //numberOfItems=0; private static String LOG = "testwidgets"; ArrayList&lt;String&gt; feedsPubDate; @TargetApi(Build.VERSION_CODES.GINGERBREAD) @SuppressWarnings("deprecation") @Override public void onStart(Intent intent, int startId) { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); Log.i(LOG, "Called"); // Create some random data feedsPubDate=new ArrayList&lt;String&gt;(); ///////////////////////////////////////////////////////////////////// // SharedPreferences sp = getSharedPreferences("updateOptions", 0); // int updatePeriod=sp.getInt("UpdatePeriod", -1); Calendar cal = Calendar.getInstance(); cal.add(Calendar.SECOND, 10); Intent intent1 = new Intent(this, UpdateWidgetServiceDemo.class); PendingIntent pintent = PendingIntent.getService(this, 0, intent1, 0); AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE); int i; i=15; alarm.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), i* 1000, pintent); } . . . </code></pre> <p>Here the main important part is : </p> <pre><code>Calendar cal = Calendar.getInstance(); cal.add(Calendar.SECOND, 10); Intent intent1 = new Intent(this, UpdateWidgetServiceDemo.class); PendingIntent pintent = PendingIntent.getService(this, 0, intent1, 0); AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE); int i; i=15; alarm.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), i* 1000, pintent); </code></pre> <p>I think your problem will be solved.</p> <p>Enjoy!!!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload