I would like to develop a widget for a existing android apps.
The only function i want is to display the variable i get from the apps.
I have developed a simple function to get variable from it but i don’t know how to update it when the apps is closed.
Or i have to write a service to get these variable?
package hkcsl.tabbedactivealarm;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.RemoteViews;
public class AppWidgetExample extends AppWidgetProvider {
@Override
public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.helloworld);
String value1 = intent.getStringExtra("Value");
views.setTextViewText(R.id.text, value1);
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
appWidgetManager.updateAppWidget(new ComponentName(context, AppWidgetExample.class), views);
}
}
if i understand the question –
Yes, it’s possible, but i believe that the update interval must be less frequent than once per minute. refer to this guide for a simple tutorial:
http://www.vogella.com/articles/AndroidWidgets/article.html#simplewidget
Yeah, your app needs a process that runs while your app is closed. so a background service or an AsyncTask or Thread would do. Background Service is your best choice
edit
okay i think i undersatnd better now. using that same link above, read section 4.
you only start 1 service, and the service takes care of updating values. if you want something special to happen upon the user exiting your app, you can override
onDestroy()?edit 2
use something like this in the XML:
notice the
updatePeriodMillis=300000this was taken from section 3 of that article link above