Source:
private void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) { RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.pinned_note_widget); SharedPreferences prefs = context.getSharedPreferences("com.automattic.simplenote", Context.MODE_PRIVATE); String key = prefs.getString(Integer.toString(appWidgetId), ""); if (!key.isEmpty()) { Simplenote currentApp = (Simplenote) context.getApplicationContext(); Bucket<Note> mNotesBucket = currentApp.getNotesBucket(); try { Note updatedNote = mNotesBucket.get(key); Bundle arguments = new Bundle(); arguments.putString(NoteEditorFragment.ARG_ITEM_ID, updatedNote.getSimperiumKey()); arguments.putBoolean(NoteEditorFragment.ARG_MARKDOWN_ENABLED, updatedNote.isMarkdownEnabled()); Intent intent = new Intent(context, NoteEditorActivity.class); intent.putExtras(arguments); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, intent, 0); views.setOnClickPendingIntent(R.id.widget_layout, pendingIntent); views.setTextViewText(R.id.widget_text, updatedNote.getTitle()); appWidgetManager.updateAppWidget(appWidgetId, views); } catch (BucketObjectMissingException e) { views.setTextViewText(R.id.widget_text, "Note Not Found"); appWidgetManager.updateAppWidget(appWidgetId, views); } } else { views.setTextViewText(R.id.widget_text, "Note Not Found"); appWidgetManager.updateAppWidget(appWidgetId, views); } }

Target:
private void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) { RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.pinned_note_widget); Simplenote currentApp = (Simplenote) context.getApplicationContext(); Simperium simperium = currentApp.getSimperium(); User user = simperium.getUser(); if(user.getStatus().equals(User.Status.NOT_AUTHORIZED)) { views.setOnClickPendingIntent(R.id.widget_layout, null); views.setTextViewText(R.id.widget_text, context.getResources().getString(R.string.widget_signed_out)); } else { String key = PrefUtils.getStringPref(context, PrefUtils.PREF_PINNED_NOTE_WIDGET_NOTE + appWidgetId); if (!key.isEmpty()) { Bucket<Note> notesBucket = currentApp.getNotesBucket(); try { Note updatedNote = notesBucket.get(key); Bundle arguments = new Bundle(); arguments.putString(NoteEditorFragment.ARG_ITEM_ID, updatedNote.getSimperiumKey()); arguments.putBoolean(NoteEditorFragment.ARG_MARKDOWN_ENABLED, updatedNote.isMarkdownEnabled()); Intent intent = new Intent(context, NoteEditorActivity.class); intent.putExtras(arguments); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, intent, 0); views.setOnClickPendingIntent(R.id.widget_layout, pendingIntent); views.setTextViewText(R.id.widget_text, updatedNote.getTitle()); } catch (BucketObjectMissingException e) { views.setOnClickPendingIntent(R.id.widget_layout, null); views.setTextViewText(R.id.widget_text, context.getResources().getString(R.string.widget_note_not_found)); } } else { views.setOnClickPendingIntent(R.id.widget_layout, null); views.setTextViewText(R.id.widget_text, context.getResources().getString(R.string.widget_note_not_found)); } } appWidgetManager.updateAppWidget(appWidgetId, views); }