Note that there are some explanatory texts on larger screens.

plurals
  1. POClock Widget Killed
    text
    copied!<p>I created app with widget that have clock, the problem is after approximately half hour the clock stop working or when i kill the app with "Advanced Task Killer" it also stop working. How can i keep my app always alive or only the widget. Here is the class of the widget:</p> <pre><code>package com.shamir; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import android.app.PendingIntent; import android.appwidget.AppWidgetManager; import android.appwidget.AppWidgetProvider; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.os.Handler; import android.widget.RemoteViews; public class Widget extends AppWidgetProvider { private Handler mHandler = new Handler(); RemoteViews views; AppWidgetManager appWidgetManager; ComponentName currentWidget; Context context; DateFormat time_format = new SimpleDateFormat("HH:mm:ss"); DateFormat date_format = new SimpleDateFormat("dd.MM.yy"); public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { this.context = context; this.appWidgetManager = appWidgetManager; views = new RemoteViews(context.getPackageName(), R.layout.widget); currentWidget = new ComponentName(context, Widget.class); mHandler.removeCallbacks(mUpdateTask); mHandler.postDelayed(mUpdateTask, 100); } final Runnable mUpdateTask = new Runnable() { public void run() { Intent informationIntent = new Intent(context,MainScreen.class); PendingIntent infoPendingIntent = PendingIntent.getActivity(context, 0, informationIntent, 0); views.setOnClickPendingIntent(R.id.w_start, infoPendingIntent); views.setTextViewText(R.id.widget_time,time_format.format(new Date())); views.setTextViewText(R.id.widget_date,date_format.format(new Date())); appWidgetManager.updateAppWidget(currentWidget, views); mHandler.postDelayed(mUpdateTask, 1000); } }; @Override public void onDisabled(Context context) { super.onDisabled(context); mHandler.removeCallbacks(mUpdateTask); } </code></pre> <p>}</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