Created
December 11, 2016 16:44
-
-
Save yerenutku/f71f1522f01b5ced9f4cdec9a84c4496 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class UpdateService extends Service { | |
@Nullable | |
@Override | |
public IBinder onBind(Intent intent) { | |
return null; | |
} | |
@Override | |
public int onStartCommand(Intent intent, int flags, int startId) { | |
// generates random number | |
Random random = new Random(); | |
int randomInt = random.nextInt(100); | |
String lastUpdate = "R: "+randomInt; | |
// Reaches the view on widget and displays the number | |
RemoteViews view = new RemoteViews(getPackageName(), R.layout.updating_widget); | |
view.setTextViewText(R.id.tvWidget, lastUpdate); | |
ComponentName theWidget = new ComponentName(this, UpdatingWidget.class); | |
AppWidgetManager manager = AppWidgetManager.getInstance(this); | |
manager.updateAppWidget(theWidget, view); | |
return super.onStartCommand(intent, flags, startId); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment