Search code examples
androidwidgethideinvisible

make android widget invisible when start activity


i have widget and when i click on it i'm starting new activity with transparent backround and i wanna hide that widget so only the activity is present on the homescreen or find a way to put the activity window on the top of the widget but i cant use intent.getSourceBounds method cause i'm not using API level 7 or above


Solution

  • I found the solution

         public class homeWidget extends AppWidgetProvider {
    public static String ACTION_WIDGET_RECEIVER = "ActionReceiverWidget";
     @Override
        public void onUpdate( Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds )
        {
            RemoteViews remoteViews;
            ComponentName watchWidget;
    
            Intent active = new Intent(context, homeWidget.class);
            active.setAction(ACTION_WIDGET_RECEIVER);
            PendingIntent actionPendingIntent = PendingIntent.getBroadcast(context, 0, active, 0);
    
    
            remoteViews = new RemoteViews( context.getPackageName(), R.layout.widget );
            watchWidget = new ComponentName( context, homeWidget.class );
    
            remoteViews.setOnClickPendingIntent(R.id.buttonWidget1, actionPendingIntent);
    
    
    
            appWidgetManager.updateAppWidget( watchWidget, remoteViews );
        }
     @Override
     public void onEnabled(Context context){
         AppWidgetManager mgr = AppWidgetManager.getInstance(context); 
         RemoteViews remoteViews;
            ComponentName watchWidget;
    
            Intent active = new Intent(context, homeWidget.class);
            active.setAction(ACTION_WIDGET_RECEIVER);
            PendingIntent actionPendingIntent = PendingIntent.getBroadcast(context, 0, active, 0);
    
    
            remoteViews = new RemoteViews( context.getPackageName(), R.layout.widget );
            watchWidget = new ComponentName( context, homeWidget.class );
    
            remoteViews.setOnClickPendingIntent(R.id.buttonWidget1, actionPendingIntent);
    
            mgr.updateAppWidget(watchWidget,remoteViews);
    
     }
     @Override
     public void onReceive(Context context, Intent intent) {
         AppWidgetManager mgr = AppWidgetManager.getInstance(context); 
         if (intent.getAction().equals(ACTION_WIDGET_RECEIVER)) {
             Log.i("proverka", "uleva");
             Intent intent1 = new Intent(context,widget_activity.class);
             PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent1, 0);
             RemoteViews remoteViews;
             remoteViews = new RemoteViews( context.getPackageName(), R.layout.widget );
    
             ComponentName watchWidget;
             watchWidget = new ComponentName( context, homeWidget.class );
    
             remoteViews.setViewVisibility(R.id.LinearLayout01, View.GONE);
             try {
                pendingIntent.send();
            } catch (CanceledException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
    
    
    
             mgr.updateAppWidget(watchWidget,remoteViews);
             }
             super.onReceive(context, intent);
     }
    
     }