I am new to this and this is a big headache for me. I have a widget with a provider, a config and an extra activity which is called when you click on the widget. I need to determine the widget ID in the activity.
In the provider I set it to call the activity from onUpdate with a .setOnClickPendingIntent, and in the intent I add the widget ID. When I try to get the widget ID from the intent in the activity, it is always 0 (but the activity is called fine). I can retrieve the ID in the config but not in the activity with the same code.
I'm sure it will be something basic/an amateur mistake. Your help is appreciated!
Truncated code:
Provider:
public static String ACTION_WIDGET_CLICK = "ClickWidget";
#Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
ComponentName thisWidget = new ComponentName(context,
HelloWidgetProvider.class);
int[] allWidgetIds = appWidgetManager.getAppWidgetIds(thisWidget);
for (int widgetId : allWidgetIds) {
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
Intent clickIntent = new Intent(context, test.class);
clickIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
clickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
clickIntent.setAction(ACTION_WIDGET_CLICK);
PendingIntent clickPendingIntent = PendingIntent.getActivity(context, 0, clickIntent, 0);
views.setOnClickPendingIntent(R.id.update, clickPendingIntent);
appWidgetManager.updateAppWidget(widgetId, views);
}
}
So on click, it will call the pendingIntent which will call the activity defined by ACTION_WIDGET_CLICK. Manifest:
<activity android:name=".test">
<intent-filter>
<action
android:name="com.example.widget_create.HelloWidgetProvider.ACTION_WIDGET_CLICK"/>
</intent-filter>
</activity>
So this calls the test actvity:
public class test extends Activity {
int mAppWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent clickIntent = getIntent();
Bundle extras = intent.getExtras();
if (extras != null) {
mAppWidgetId = extras.getInt(
AppWidgetManager.EXTRA_APPWIDGET_ID,
AppWidgetManager.INVALID_APPWIDGET_ID);
}
}
It doesn't receive the extras and then the widget ID gets set to 0
If the same value is given by getExtras in (for example) the activity, you must change the requestCode (perhaps to the widgetid)
Intent clickIntent = new Intent(context,ActivityName.class);
clickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,myWidgetId);
PendingIntent pendingIntent = PendingIntent.getActivity(context, myWidgetId, clickIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
remoteViews.setOnClickPendingIntent(R.id.layout,pendingIntent);
Can you copy/paste what you get into the console log please ?
Check your Manifest file for the android:name tag, it must be android:name=".Test" with an uppercase.
At onUpdateyou are passing IDS (array of ID)
clickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
while at your activity your are asking por ID (just one ID)
mAppWidgetId = extras.getInt(
AppWidgetManager.EXTRA_APPWIDGET_ID,
AppWidgetManager.INVALID_APPWIDGET_ID);
As you are inside a for looping throught every widget ID, you should change the intent at the provider with:
clickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId);
Notice the EXTRA_APPWIDGET_ID and the widgetId value instead of the old appWidgetIds.
Related
I've been searching for a while on here, but can't find a solution to this. I have a home screen widget with a configuration screen that saves some parameters inside the preferences. The configuration part works flawlessly, but I cannot for the life of me get the setOnClickPendingIntent to register. No error messages.
AndroidManifest.xml
<receiver android:name=".TrunkWidget">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
<action android:name="ActionTrunkButtonClicked" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="#xml/trunk_widget_info" />
</receiver>
My App widget provider:
public class TrunkWidget extends AppWidgetProvider {
private SharedPreferences pref;
private final String clickAction = "ActionTrunkButtonClicked";
// UPDATE FUNCTION
static void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
int appWidgetId) {
// Construct the RemoteViews object
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.trunk_widget);
// Instruct the widget manager to update the widget
appWidgetManager.updateAppWidget(appWidgetId, views);
}
#Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
// There may be multiple widgets active, so update all of them
for (int appWidgetId : appWidgetIds) {
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.trunk_widget);
// Register an onClickListener
Intent intent = new Intent(context, TrunkWidget.class);
intent.setAction(clickAction);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
//Set pendingIntent
PendingIntent pendingIntent = PendingIntent.getBroadcast(context,0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
remoteViews.setOnClickPendingIntent(R.id.my_btn, pendingIntent);
appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
updateAppWidget(context, appWidgetManager, appWidgetId);
}
}
#Override
public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
String action = intent.getAction();
String actionName = clickAction;
if (actionName.equals(action)) {
//DO STUFF
}
}
I'm pulling my hair on this...if anyone has any idea, I'd be grateful.
Thanks!
Nevermind. I moved this part :
// Register an onClickListener
Intent intent = new Intent(context, TrunkWidget.class);
intent.setAction(clickAction);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
//Set pendingIntent
PendingIntent pendingIntent = PendingIntent.getBroadcast(context,0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
remoteViews.setOnClickPendingIntent(R.id.my_btn, pendingIntent);
appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
From onUpdate() to updateAppWidget() and now it works. I'm leaving this here in case someone needs it.
I have a calendar widget and I'm updating it myself everyday at 12:01AM as well when the size is changed so I don't have a need for automatic update. I also set the updatePeriodMillis to 0. The problem I'm having is that the App Widget calls onAppWidgetOptionsChanged():
Every time the screen unlocks
Every time you're brought home
It wouldn't be an issue for me, but the problem is you can see for a split second the App Widget updating. Anyone know of any way I can prevent that from happening?
For reference here is part of my WidgetProvider class
#Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action != null) {
if (action.equals(ACTION_REFRESH) || action.equals(ACTION_NEXT) || action.equals(ACTION_PREVIOUS)) {
context.sendBroadcast(new Intent(action));
}
}
Bundle extra = intent.getExtras();
if (extra != null && extra.containsKey(KEY_APP_WIDGET_ID)) {
updateAppWidget(context, AppWidgetManager.getInstance(context), extra.getInt(KEY_APP_WIDGET_ID));
}
super.onReceive(context, intent);
}
#Override
public void onAppWidgetOptionsChanged(Context context, AppWidgetManager appWidgetManager, int appWidgetId, Bundle newOptions) {
int width = Util.dp2px(newOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH));
Intent broadcastIntent = new Intent(ACTION_REFRESH);
broadcastIntent.putExtra(KEY_SIZE_CHANGE, width);
context.sendBroadcast(broadcastIntent);
updateAppWidget(context, appWidgetManager, appWidgetId);
super.onAppWidgetOptionsChanged(context, appWidgetManager, appWidgetId, newOptions);
}
private static void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
int appWidgetId) {
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
Intent intent = new Intent(context, WidgetService.class);
views.setRemoteAdapter(R.id.widget_calendar_container, intent);
// Buttons on widget click handlers
views.setOnClickPendingIntent(R.id.widget_refresh, getPendingSelfIntent(context, ACTION_REFRESH, appWidgetId));
views.setOnClickPendingIntent(R.id.widget_next, getPendingSelfIntent(context, ACTION_NEXT, appWidgetId));
views.setOnClickPendingIntent(R.id.widget_previous, getPendingSelfIntent(context, ACTION_PREVIOUS, appWidgetId));
// Widget Container click handler
Intent homeIntent = new Intent(Intent.ACTION_MAIN);
homeIntent.addCategory(Intent.CATEGORY_LAUNCHER);
homeIntent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
homeIntent.setComponent(new ComponentName(context.getPackageName(), Home.class.getName()));
PendingIntent homePendingIntent = PendingIntent.getActivity(context, 0, homeIntent, 0);
views.setPendingIntentTemplate(R.id.widget_calendar_container, homePendingIntent);
// Instruct the widget manager to update the widget
appWidgetManager.updateAppWidget(appWidgetId, views);
appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetId, R.id.widget_calendar_container);
}
I prefer another answer, but this is what I got so far.
#Override
public void onAppWidgetOptionsChanged(Context context, AppWidgetManager appWidgetManager, int appWidgetId, Bundle newOptions) {
int width = Util.dp2px(newOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH));
if (width != WidgetRemoteViewsFactory.width) {
Intent broadcastIntent = new Intent(ACTION_REFRESH);
broadcastIntent.putExtra(KEY_SIZE_CHANGE, width);
LocalBroadcastManager.getInstance(context).sendBroadcast(broadcastIntent);
updateAppWidget(context, appWidgetManager, appWidgetId);
super.onAppWidgetOptionsChanged(context, appWidgetManager, appWidgetId, newOptions);
}
}
I made the field I am interested in width static on WidgetRemoteViewsFactory and I am only broadcasting when that field changes. I can't seem to prevent onAppWidgetOptionsChanged() from being called because AppWidgetManager.ACTION_APPWIDGET_OPTIONS_CHANGED is being broadcasted and received every time the screen is awaken.
Android Documentation says
Called in response to the AppWidgetManager.ACTION_APPWIDGET_OPTIONS_CHANGED broadcast when this widget has been layed out at a new size. -
AppWidgetProvider#onAppWidgetOptionsChanged
But that action is being broadcasted every time the screen awakens.
If anyone has a better solution, please feel free to post it. There has to be a better solution or this is a bug on Android's side.
I have seen related questions for this issue but I'am unable to figure out why this is not working for me.
I am expecting for onReceive() method in Widget Provider class to be called as the list item is clicked, but nothing happens.
Some comments are included, and they show what I have been trying as well.
Relevant code:
Main app layout has ListView defined like this:
<ListView
android:id="#+id/events_list"
style="#android:style/TextAppearance.Small"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
Row is defined with RelativeLayout with two nested Linear layouts, not sure if this is important to share.
getViewAt() is implemented through view factory and here's the function:
#Override
public RemoteViews getViewAt(int position) {
if (events_ack == null) {
Log.e("LIST", "getViewAt (null) events_ack");
return null;
}
RemoteViews row = new RemoteViews(context.getPackageName(), R.layout.row);
row.setTextViewText(R.id.event_name, events_ack[position].name);
row.setTextViewText(R.id.description, events_ack[position].description);
row.setTextViewText(R.id.publicTV, (events_ack[position].is_public == 0) ? "Public: False" : "Public: True");
row.setTextViewText(R.id.timeTV, events_ack[position].time);
row.setViewVisibility(R.id.price, View.GONE);
// download and set image BONUS QUESTION- does not work through AsyncTask using future insted (images are downloaded but not shown).
row.setImageViewBitmap(R.id.image, pic);
Bundle extras = new Bundle();
extras.putInt(CasusWidgetProvider.EXTRA_WORD, events_ack[position].id);
Intent fillInIntent = new Intent();
fillInIntent.putExtras(extras);
// Make it possible to distinguish the individual on-click
// action of a given item
row.setOnClickFillInIntent(R.id.events_list, fillInIntent);
//extras.putInt(CasusWidgetProvider.EXTRA_WORD, events_ack[position].id);
//i.putExtras(extras);
//i.setAction(CasusWidgetProvider.ITEM_CLICK);
//row.setOnClickFillInIntent(R.layout.casus_widget, i); //event_name?
// ??
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.casus_widget);
appWidgetManager.updateAppWidget(appWidgetId, rv);
//appWidgetManager.updateAppWidget(appWidgetId, row);
return row;
}
Widget Provider class has onUpdate() method:
#Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
Log.w("CASUS", "UPDATE function called");
for (int i = 0; i < appWidgetIds.length; i++) {
Intent intent = new Intent(context, WidgetService.class);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]);
intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.casus_widget);
rv.setRemoteAdapter(appWidgetIds[i], R.id.events_list, intent);
Intent clickIntent=new Intent(context, WidgetService.class);
clickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]);
clickIntent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
clickIntent.setAction(ITEM_CLICK);
PendingIntent clickPI = PendingIntent.getActivity(context, 0, clickIntent, PendingIntent.FLAG_UPDATE_CURRENT);
rv.setPendingIntentTemplate(R.id.events_list, clickPI);
appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds[i], R.id.events_list); //?
clickIntent = new Intent(context, CasusWidgetProvider.class);
clickIntent.setAction(UPDATE_LIST);
clickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
PendingIntent pendingIntentRefresh = PendingIntent.getBroadcast(context, 0, clickIntent, 0);
rv.setOnClickPendingIntent(R.id.update, pendingIntentRefresh);
appWidgetManager.updateAppWidget(appWidgetIds[i], rv);
}
fetchData(context, appWidgetIds);
super.onUpdate(context, appWidgetManager, appWidgetIds);
}
I have figured it out. onUpdate() function in widget provider class was modified to look like this:
#Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
for (int i = 0; i < appWidgetIds.length; i++) {
Intent intent = new Intent(context, WidgetService.class);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]);
intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.casus_widget);
rv.setRemoteAdapter(appWidgetIds[i], R.id.events_list, intent);
appWidgetManager.updateAppWidget(appWidgetIds[i], rv);
}
fetchData(context, appWidgetIds);
super.onUpdate(context, appWidgetManager, appWidgetIds);
}
In getViewAt() function on widget factory this line:
row.setOnClickFillInIntent(R.id.events_list, fillInIntent);
Was modified to match correct ID:
row.setOnClickFillInIntent(R.id.row_layout, fillInIntent);
The click handler template is set in class that does the HTTP request, basically:
for (int widgetId : allWidgetIds) {
RemoteViews remoteViews = new RemoteViews(this.getApplicationContext().getPackageName(), R.layout.casus_widget);
Intent svcIntent = new Intent(this.getApplicationContext(), WidgetService.class);
svcIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId);
svcIntent.putExtra("events", events);
svcIntent.setData(Uri.parse(svcIntent.toUri(Intent.URI_INTENT_SCHEME)));
remoteViews.setRemoteAdapter(widgetId, R.id.events_list, svcIntent);
Intent clickIntent = new Intent(this.getApplicationContext(), CasusWidgetProvider.class);
clickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, allWidgetIds);
clickIntent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
clickIntent.setAction(CasusWidgetProvider.ITEM_CLICK);
PendingIntent toastPendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(), 0, clickIntent, PendingIntent.FLAG_UPDATE_CURRENT);
remoteViews.setPendingIntentTemplate(R.id.events_list, toastPendingIntent);
appWidgetManager.updateAppWidget(widgetId, remoteViews);
}
Hope this might help..
I would like to know how to bypass the "Touch to Configure" on my android widget programmatically. Once I have installed the android widget on my device it says "Touch to configure" which then executes my class "IntelligenWidgetConfig.java". But I want this to automatically happen on start up of my application. Can anyone advise me on how to approach this method or any solution that might help?
Android Config Class:
public class IntelliGenWidgetConfig extends Activity {
private static final String TAG = "IntelliGenWidgetConfig";
public IntelliGenWidgetConfig() {
super();
}
public static int getAppWidgetId(Context context) {
SharedPreferences settings = context.getSharedPreferences("Intelligen", MODE_PRIVATE);
return settings.getInt("appWidgetId", 1);
}
protected void setAppWidgetId(int id) {
SharedPreferences settings = getSharedPreferences("Intelligen", MODE_PRIVATE);
SharedPreferences.Editor editor = settings.edit();
editor.putInt("appWidgetId", id);
editor.commit();
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set the result to CANCELED. This will cause the widget host to cancel
// out of the widget placement if they press the back button.
setResult(RESULT_CANCELED);
// Find the widget id from the intent.
Intent intent = getIntent();
Bundle extras = intent.getExtras();
if (extras != null) {
setAppWidgetId(extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID));
}
// If they gave us an intent without the widget id, just bail.
if (getAppWidgetId(this) == AppWidgetManager.INVALID_APPWIDGET_ID) {
finish();
}
final Context context = IntelliGenWidgetConfig.this;
RegisterForPushNotification(context);
// Push widget update
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.intelligen_widget_layout);
appWidgetManager.updateAppWidget(getAppWidgetId(this), views);
// Make sure we pass back the original appWidgetId
Intent resultValue = new Intent();
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, getAppWidgetId(this));
setResult(RESULT_OK, resultValue);
finish();
}
private void RegisterForPushNotification(Context ctx) {
Intent registerIntent = new Intent("com.google.android.c2dm.intent.REGISTER");
registerIntent.putExtra("app", PendingIntent.getBroadcast(ctx, 0, new Intent(), 0));
registerIntent.putExtra("sender", "209845001369");
startService(registerIntent);
}
private void DeregisterFromPushNotification(Context ctx) {
Intent unregisterIntent = new Intent("com.google.android.c2dm.intent.UNREGISTER");
unregisterIntent.putExtra("app", PendingIntent.getBroadcast(ctx, 0, new Intent(), 0));
startService(unregisterIntent);
}
}
AndroidManifest.xml (section):
<activity android:name=".IntelliGenWidgetConfig" android:label="#string/app_name">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE"/>
</intent-filter>
</activity>
XML
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider
xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="180dp"
android:minHeight="360dp"
android:updatePeriodMillis="0"
android:initialLayout="#layout/intelligen_widget_layout"
android:resizeMode="vertical"
android:minResizeWidth="280dp"
android:minResizeHeight="70dp"
android:configure="za.co.infotech.www.intelligen.IntelliGenWidgetConfig"
android:previewImage="#drawable/preview">
</appwidget-provider>
I have this widget in android, that displays an image and gets updated periodically by a broadcast receiver. Now I want to give the user the ability to start a configuration screen (preference activity) by clicking on the widget. Here it goes:
The widget provider class:
public class MyProvider extends AppWidgetProvider {
#Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
ComponentName thisWidget = new ComponentName(context.getApplicationContext(), MyProvider.class);
int[] allWidgetIds = appWidgetManager.getAppWidgetIds(thisWidget);
RemoteViews rViews = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
for (int widgetId : appWidgetIds) {
// setting onClickListener - at least i TRY to
Intent onClickIntent = new Intent(context, Preferences.class);
PendingIntent onClickPendingIntent = PendingIntent.getBroadcast(context, 0, onClickIntent, 0);
rViews.setOnClickPendingIntent(R.id.graph, onClickPendingIntent);
appWidgetManager.updateAppWidget(widgetId, rViews);
}
}
}
The updates of the widget are triggered from here:
public class MyReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context.getApplicationContext());
int[] allWidgetIds = intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS);
ComponentName myWidget = new ComponentName(context.getApplicationContext(), MyProvider.class);
int[] allMyWidgetIds = appWidgetManager.getAppWidgetIds(myWidget);
for (int widgetId : allMyWidgetIds)
{
RemoteViews rViews = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
// update the widgets content, i.e. picture
appWidgetManager.updateAppWidget(widgetId, rViews);
}
// schedule next update
Calendar c = Calendar.getInstance();
c.add(Calendar.SECOND, Config.UPDATE_RATE);
Date d = new Date(c.getTimeInMillis());
Intent timerIntent = new Intent(context.getApplicationContext(), TimeIntervalReceiver.class);
timerIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, allWidgetIds);
PendingIntent timerPendingIntent = PendingIntent.getBroadcast(context.getApplicationContext(), 0, timerIntent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager aManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
aManager.set(AlarmManager.RTC, d.getTime(), timerPendingIntent);
}
}
Just to mention it: the Preference.java-Activity is registered in the Manifest and can be started correctly (I verified this by setting it as the startup activity).
Anyhow, the onclick-functionality does not work at all :(
I also tried to move the code to the "MyReceiver"-class which updates the widgets: nothing :(
I already looked at:
* Android: Clickable imageview widget
* http://www.vogella.de/articles/AndroidWidgets/article.html
However, this didn't help at all :(
anyone here who can tell me where my problem is?
Try changing this line:
PendingIntent onClickPendingIntent = PendingIntent.getBroadcast(context, 0, onClickIntent, 0);
to
PendingIntent onClickPendingIntent = PendingIntent.getActivity(context, 0, onClickIntent, 0);
PendingIntent onClickPendingIntent = PendingIntent.getActivity(context, 0, onClickIntent, 0);
Retrieve a PendingIntent that will start a new activity
http://developer.android.com/reference/android/app/PendingIntent.html#getActivity(android.content.Context, int, android.content.Intent, int)
Plz refer link for full reference