Reputation: 6323
I am completly new to android programming and I try to get clicking on an android widget working:
public class MyWidget extends AppWidgetProvider {
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds)
{
// Loop through all widgets
for(int i=0;i < appWidgetIds.length;i++) {
int appWigedid = appWidgetIds[i];
// Create an intent to launce something
Intent intent = new Intent(context,TestActivity.class);
PendingIntent pendingintent = PendingIntent.getActivity(context, 0, intent, 0);
// Get the layout for the app widget and attach on click listener
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.initial_layout);
views.setOnClickPendingIntent(R.id.UselessMessage, pendingintent);
views.setTextViewText(R.id.UselessMessage,"This text is useless");
AppWidgetManager manager = AppWidgetManager.getInstance(context);
manager.updateAppWidget(appWigedid,views);
}
}
my TestActivity class is just a stub because still trying to find out how it is called.
public class TestActivity extends Activity {
@Override
protected void onStart() {
System.out.println("On Start called!");
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
System.out.println("on create called!");
};
}
The setting of the Text works. But the onStart method of the TestAcitivity is never executed (other sysout messages work). When I tap on the widget android logs:
12-25 17:17:43.054 1279 1392 I ActivityManager: Starting activity: Intent { flg=0x10000000 cmp=org.rfc1149.android.simple/.TestActivity bnds=[120,272][360,371] }
which would suggest that the activity is created but the onCreate does not work.
Upvotes: 1
Views: 1910
Reputation: 2981
Use Log.d("myTAG", "debug text")
instead of System.out.println("debug text")
Upvotes: 0
Reputation: 11923
Your onCreate() method does work and will log to the LogCat which is viewable on the DDMS perspective (if your using Eclipse).For your onStart() method to work, you must call super.onStart() in your overriden onStart() method.
Upvotes: 0