Note that there are some explanatory texts on larger screens.

plurals
  1. POHiding main activity when widget is tapped
    text
    copied!<p>I have developed an app widget for android which when tapped, an activity with a Dialog Theme appears. However if from the main activity the home button is pressed and then try to tap the widget again, the main activity appears on the background. Is there a way to prevent this from happening? i.e main activity not to appear when widget is tapped anifest</p> <p>AndroidManifest.xml</p> <pre><code>&lt;receiver android:name=".myWidget" &gt; &lt;intent-filter&gt; &lt;action android:name="android.appwidget.action.APPWIDGET_UPDATE" /&gt; &lt;/intent-filter&gt; &lt;meta-data android:name="android.appwidget.provider" android:resource="@xml/res_widget" /&gt; &lt;/receiver&gt; </code></pre> <p>AppWidgetProvider.java</p> <pre><code>public void onUpdate(Context c, AppWidgetManager appWidgetManager,int[] appWidgetIds) { final int N = appWidgetIds.length; for (int i=0; i&lt;N; i++) { int appWidgetId = appWidgetIds[i]; RemoteViews views = new RemoteViews(c.getPackageName(), R.layout.widget_layout); Intent fireDialog = new Intent(c,Execute.class); fireDialog.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // if i click home when i am in main activity i still get it on background-this doesnt help neither though PendingIntent pendingIntent = PendingIntent.getActivity(c, 0, fireDialog, 0); views.setOnClickPendingIntent(R.id.myButton, pendingIntent); Log.w(LOG_TAG,"Called"); appWidgetManager.updateAppWidget(appWidgetId, views); } } public void onReceive(Context c, Intent intent) { final String action=intent.getAction(); if(AppWidgetManager.ACTION_APPWIDGET_DELETED.equals(action)){ final int appWidgetId=intent.getExtras().getInt(AppWidgetManager.EXTRA_APPWIDGET_ID,AppWidgetManager.INVALID_APPWIDGET_ID); if(appWidgetId!=AppWidgetManager.INVALID_APPWIDGET_ID){ this.onDeleted(c,new int[]{appWidgetId}); } }else{ super.onReceive(c, intent); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload