[Java for Android App Development] hiphop12ism:
Hey, fellas.. I was learning about widgets. But I got stuck at the very beginning. I was trying to make the simplest of a widget. Firstly, I made an app, that only has one textview on it. When clicked , it shows the number of times it has been clicked. Then I tried to make a widget of the same.

But when I click over the widget, nothing happens. It just shows the initialized number '0'. The debugging goes fine. There is no ANR errors.

But I am not able to figure out the logical error. As the debugging goes alright, I don't think, the logcat will be necessary.

However, If required , I will provide it too. For now, I am uploading the AppWidget.class, widget.xml, manifest.xml, widget_provider.xml :::

THE APPWIDGET.CLASS:

package com.example.increment;

import android.app.IntentService;
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.widget.RemoteViews;

public class AppWidget extends AppWidgetProvider {
int c = 0;
[MENTION=439709]override[/MENTION]
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
if (intent.getAction() == null)
context.startService(new Intent(context, ToggleService.class));
else
super.onReceive(context, intent);
}

[MENTION=439709]override[/MENTION]
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
// TODO Auto-generated method stub
super.onUpdate(context, appWidgetManager, appWidgetIds);
}

private class ToggleService extends IntentService {

public ToggleService() {
super("AppWidget$ToggleService");
// TODO Auto-generated constructor stub
}

[MENTION=439709]override[/MENTION]
protected void onHandleIntent(Intent intent) {
// TODO Auto-generated method stub

ComponentName me = new ComponentName(this, AppWidget.class);
AppWidgetManager mgr = AppWidgetManager.getInstance(this);
mgr.updateAppWidget(me, buildUpdate(this));

}

private RemoteViews buildUpdate(Context context) {
// TODO Auto-generated method stub

RemoteViews rm = new RemoteViews(context.getPackageName(),
R.layout.widget);

c++;
String s = String.valueOf(c);
rm.setTextViewText(R.id.t2, s);
Intent i = new Intent(this, AppWidget.class);
PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, 0);
rm.setOnClickPendingIntent(R.id.t2, pi);
return rm;

}

}

}

THE WIDGET.XML

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<TextView
android:id="@+id/t2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:clickable="true" />

</LinearLayout>

THE WIDGET_PROVIDER.XML:

<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minHeight="100sp"
android:minWidth="100sp"
android:updatePeriodMillis="1000"
android:initialLayout="@layout/widget">

</appwidget-provider>

THE MANIFEST.XML:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.increment"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.increment.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<receiver
android:name="com.example.increment.AppWidget"
android:icon="@drawable/ic_launcher"
android:label="tanmay" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>

<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/widget_provider" />
</receiver>

<service android:name=".AppWidget$ToggleService" >
</service>
</application>

</manifest>

Thanks in advance.. :)