Java Question Permission denied for this window type

XverhelstX

Well-Known Member
Licensed User
Longtime User
I'm trying to port a new library: StandOut.
[APP][2.1+] StandOut - Create Floating Apps [Updated 7/8: Window Editor] - xda-developers

It seems a lot of people are having trouble with starting activities, services, etc from a library and again, i'm having trouble too. (I don't know if it's related though.)

b4a code

B4X:
'Activity module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   Dim StandOut As RSStandOut
   Dim mbw As RSMostBasicWindow
   Dim pnlBasic As Panel
End Sub

Sub Activity_Create(FirstTime As Boolean)

   'Load activity stuff
   Activity.AddMenuItem("Show Basic", "mnuShowBasic")
   
   'Initialize BasicWindow Panel
   pnlBasic.Initialize("BasicWindow")
   pnlBasic.LoadLayout("BasicWindow.bal")
   
   'Initialize StandOut
   StandOut.Initialize("StandOut")
   'StandOut.createBasicWindow(pnlBasic)

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub mnuShowBasic_Click
   StandOut.showBasicWindow
   'StartService(Window)
   'Activity.Finish
End Sub

This log happens after clicking the menu:

View attached!


android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRoot$W@2b009e10 -- permission denied for this window type


at android.view.ViewRoot.setView(ViewRoot.java:570)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
at com.rootsoft.standout.StandOutWindow.show(StandOutWindow.java:1440)
at com.rootsoft.standout.StandOutWindow.onStartCommand(StandOutWindow.java:716)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2060)
at android.app.ActivityThread.access$2800(ActivityThread.java:121)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1006)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3701)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)


at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
at dalvik.system.NativeStart.main(Native Method)
Error showing notification for service


java.lang.IllegalArgumentException: contentIntent required: pkg=com.rootsoft.standout id=721247375 notification=Notification(vibrate=null,sound=null,defaults=0x0,flags=0x60)
at com.android.server.NotificationManagerService.enqueueNotificationInternal(NotificationManagerService.java:790)
at com.android.server.am.ServiceRecord$1.run(ServiceRecord.java:342)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at com.android.server.am.ActivityManagerService$AThread.run(ActivityManagerService.java:1366)
Shutting down VM
threadid=1: thread exiting with uncaught exception (group=0x2aac8578)


android.app.RemoteServiceException: Bad notification for startForeground: java.lang.IllegalArgumentException: contentIntent required: pkg=com.rootsoft.standout id=721247375 notification=Notification(vibrate=null,sound=null,defaults=0x0,flags=0x60)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1056)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3701)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
at dalvik.system.NativeStart.main(Native Method)
FATAL EXCEPTION: main
android.app.RemoteServiceException: Bad notification for startForeground: java.lang.IllegalArgumentException: contentIntent required: pkg=com.rootsoft.standout id=721247375 notification=Notification(vibrate=null,sound=null,defaults=0x0,flags=0x60)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1056)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3701)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
at dalvik.system.NativeStart.main(Native Method)
Force finishing activity com.rootsoft.standout/.main
Activity pause timeout for HistoryRecord{2b5b9720 com.rootsoft.standout/.main}

Java:
B4X:
package com.rootsoft.standout;

import android.graphics.Color;
import android.util.Log;
import android.widget.FrameLayout;
import android.widget.TextView;
import anywheresoftware.b4a.BA.ShortName;

@ShortName("RSMostBasicWindow")
public class MostBasicWindow extends StandOutWindow {

   @Override
   protected String getAppName() {
      return "MostBasicWindow";
   }

   @Override
   protected int getAppIcon() {
      return android.R.drawable.btn_star;
   }

   @Override
   protected void createAndAttachView(int id, FrameLayout frame) {
      Log.i("B4A", "View attached!");
      TextView view = new TextView(this);
      view.setText("MostBasicWindow");
      view.setBackgroundColor(Color.CYAN);

      frame.addView(view);
   }

   @Override
   protected LayoutParams getParams(int id, Window window) {
      return new LayoutParams(id, 200, 150, 100, 100);
   }
}

Edit after adding the system alert permission, i have the following error:

View attached!


Error showing notification for service


java.lang.IllegalArgumentException: contentIntent required: pkg=com.rootsoft.standout id=721391847 notification=Notification(vibrate=null,sound=null,defaults=0x0,flags=0x60)
at com.android.server.NotificationManagerService.enqueueNotificationInternal(NotificationManagerService.java:790)
at com.android.server.am.ServiceRecord$1.run(ServiceRecord.java:342)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at com.android.server.am.ActivityManagerService$AThread.run(ActivityManagerService.java:1366)
Shutting down VM


threadid=1: thread exiting with uncaught exception (group=0x2aac8578)


android.app.RemoteServiceException: Bad notification for startForeground: java.lang.IllegalArgumentException: contentIntent required: pkg=com.rootsoft.standout id=721391847 notification=Notification(vibrate=null,sound=null,defaults=0x0,flags=0x60)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1056)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3701)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
at dalvik.system.NativeStart.main(Native Method)
FATAL EXCEPTION: main
android.app.RemoteServiceException: Bad notification for startForeground: java.lang.IllegalArgumentException: contentIntent required: pkg=com.rootsoft.standout id=721391847 notification=Notification(vibrate=null,sound=null,defaults=0x0,flags=0x60)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1056)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3701)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
at dalvik.system.NativeStart.main(Native Method)
Force finishing activity com.rootsoft.standout/.main
Activity pause timeout for HistoryRecord{2b50e720 com.rootsoft.standout/.main}


Aggregate from 1345400923447 (log), 1345400923447 (data)


Activity destroy timeout for HistoryRecord{2b50e720 com.rootsoft.standout/.main}
 
Last edited:

XverhelstX

Well-Known Member
Licensed User
Longtime User
OKay, i got it slightly working when doing the following:

B4X:
package com.rootsoft.standout;

import android.graphics.Color;
import android.util.Log;
import android.widget.FrameLayout;
import android.widget.TextView;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.ShortName;

@ShortName("RSMostBasicWindow")
public class MostBasicWindow extends StandOutWindow {
   

   private String eventName;
   private BA ba; 

   /**
    * Initializes the StandOut library.
    * EventName - Events subs prefix. 
    */
   public void Initialize(final BA ba, String EventName) {
      this.ba = ba;
      this.eventName = EventName.toLowerCase(BA.cul);

   }
   
   /**
    * Returns the most basic window.
    * @return
    */
   public MostBasicWindow getMostBasicWindow() {
      return this;
   }

   @Override
   protected String getAppName() {
      return "MostBasicWindow";
   }

   @Override
   protected int getAppIcon() {
      return android.R.drawable.btn_star;
   }

   @Override
   protected void createAndAttachView(int id, FrameLayout frame) {
      Log.i("B4A", "View attached!");
      
      //ba.raiseEvent(this, eventName + "_createandattachview", new Object[] { id, frame } );
   }

   @Override
   protected LayoutParams getParams(int id, Window window) {
      return new LayoutParams(id, 200, 150, 100, 100);
   }
}

But when i uncommented the raise-event, it loggs me the following:

View attached!


java.lang.RuntimeException: Unable to start service com.rootsoft.standout.MostBasicWindow@41122200 with Intent { act=SHOW cmp=com.rootsoft.standout/.MostBasicWindow (has extras) }: java.lang.NullPointerException


at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2376)
at android.app.ActivityThread.access$1900(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.rootsoft.standout.MostBasicWindow.createAndAttachView(MostBasicWindow.java:49)
at com.rootsoft.standout.StandOutWindow$Window.<init>(StandOutWindow.java:2213)
at com.rootsoft.standout.StandOutWindow.show(StandOutWindow.java:1416)
at com.rootsoft.standout.StandOutWindow.onStartCommand(StandOutWindow.java:716)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2359)
... 10 more

called from this method:

B4X:
/**
    * Shows the most Basic Window.
    */
   public void showBasicWindow(MostBasicWindow mbw) {
      StandOutWindow.show(ba.applicationContext, mbw.getClass(), StandOutWindow.DEFAULT_ID);
   }

I'm guessing it's because the BA instance isn't declared correctly.
However i declare it in the initialize method.
How would i declare a BA instance directly? (constructor, getinstance)

b4a code:
B4X:
'Activity module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   Dim StandOut As RSStandOut
   Dim mbw As RSMostBasicWindow
   Dim pnlBasic As Panel
   
End Sub

Sub Activity_Create(FirstTime As Boolean)

   'Load activity stuff
   Activity.AddMenuItem("Show Basic", "mnuShowBasic")
   
   'Initialize BasicWindow Panel
   mbw.Initialize("BasicWindow")
   pnlBasic.Initialize("BasicWindow")
   pnlBasic.LoadLayout("BasicWindow.bal")
   
   'Initialize StandOut
   StandOut.Initialize("StandOut")

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub mnuShowBasic_Click
   StandOut.showBasicWindow(mbw.MostBasicWindow)
End Sub
 

XverhelstX

Well-Known Member
Licensed User
Longtime User
Still the same error:

Log:
** Activity (main) Create, isFirst = true **


** Activity (main) Resume **


** Activity (main) Pause, UserClosed = false **


** Activity (main) Resume **


View attached!


Eventname: null


java.lang.RuntimeException: Unable to start service com.rootsoft.standout.MostBasicWindow@41125450 with Intent { act=SHOW cmp=com.rootsoft.standout/.MostBasicWindow (has extras) }: java.lang.NullPointerException


at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2376)
at android.app.ActivityThread.access$1900(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.rootsoft.standout.MostBasicWindow.createAndAttachView(MostBasicWindow.java:46)
at com.rootsoft.standout.StandOutWindow$Window.<init>(StandOutWindow.java:2213)
at com.rootsoft.standout.StandOutWindow.show(StandOutWindow.java:1416)
at com.rootsoft.standout.StandOutWindow.onStartCommand(StandOutWindow.java:716)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2359)
... 10 more

StandOutDemo
B4X:
package com.rootsoft.standout;

import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.ActivityObject;
import anywheresoftware.b4a.BA.Author;
import anywheresoftware.b4a.BA.Permissions;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;

@ShortName("RSStandOut")
@Permissions(values={"android.permission.WRITE_SECURE_SETTINGS", "android.permission.READ_PHONE_STATE", "android.permission.SYSTEM_ALERT_WINDOW"})
@Author("XverhelstX")
@Version(1.0f)
@ActivityObject
public class StandOutDemo {
   
   
   private String eventName;
   private BA ba; 

   /**
    * Initializes the StandOut library.
    * EventName - Events subs prefix. 
    */
   public void Initialize(final BA ba, String EventName) {
      this.ba = ba;
      this.eventName = EventName.toLowerCase(BA.cul);
   }
   
   
   /**
    * Shows the most Basic Window.
    */
   public void showBasicWindow(MostBasicWindow mbw) {
      StandOutWindow.show(ba.context, mbw.getClass(), StandOutWindow.DEFAULT_ID);
   }
   
   /**
    * Closes the most basic window.
    */
   public void closeBasicWindow() {
      StandOutWindow.closeAll(ba.context, MostBasicWindow.class);
   }
   

}

MostBasicWindow.java
B4X:
package com.rootsoft.standout;

import android.util.Log;
import android.widget.FrameLayout;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.ShortName;

@ShortName("RSMostBasicWindow")
public class MostBasicWindow extends StandOutWindow {
   

   private String eventName;
   private BA ba; 

   /**
    * Initializes the StandOut library.
    * EventName - Events subs prefix. 
    */
   public void Initialize(final BA ba, String EventName) {
      this.ba = ba;
      this.eventName = EventName.toLowerCase(BA.cul);
   }
   
   /**
    * Returns the most basic window.
    * @return
    */
   public MostBasicWindow getMostBasicWindow() {
      return this;
   }

   @Override
   protected String getAppName() {
      return "MostBasicWindow";
   }

   @Override
   protected int getAppIcon() {
      return android.R.drawable.btn_star;
   }

   @Override
   protected void createAndAttachView(int id, FrameLayout frame) {
      Log.i("B4A", "View attached!");
      Log.i("B4A", "Eventname: " + this.eventName);
      ba.raiseEvent(this, eventName + "_createandattachview", new Object[] { id, frame } );
   }

   @Override
   protected LayoutParams getParams(int id, Window window) {
      return new LayoutParams(id, 200, 150, 100, 100);
   }
}

B4A
B4X:
'Activity module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   Dim StandOut As RSStandOut
   Dim mbw As RSMostBasicWindow
   Dim pnlBasic As Panel
   
End Sub

Sub Activity_Create(FirstTime As Boolean)

   'Load activity stuff
   Activity.AddMenuItem("Show Basic", "mnuShowBasic")
   
   'Initialize BasicWindow Panel
   mbw.Initialize("BasicWindow")
   pnlBasic.Initialize("BasicWindow")
   pnlBasic.LoadLayout("BasicWindow.bal")
   
   'Initialize StandOut
   StandOut.Initialize("StandOut")

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub mnuShowBasic_Click
   StandOut.showBasicWindow(mbw.MostBasicWindow)
End Sub
 

XverhelstX

Well-Known Member
Licensed User
Longtime User
B4X:
ba.raiseEvent(MostBasicWindow.this, eventName + "_createandattachview", new Object[] { id, frame } );

we checked the following:

B4X:
@Override
   protected void createAndAttachView(int id, FrameLayout frame) {
      Log.i("B4A", "View attached!");
      Log.i("B4A", "Eventname: " + this.eventName);
      if (ba==null) {
         Log.i("B4A", "BA Object is null");
      }
      ba.raiseEvent(MostBasicWindow.this, eventName + "_createandattachview", new Object[] { id, frame } );
   }

and it seems that ba object is null.
 

barx

Well-Known Member
Licensed User
Longtime User
Then would you need to pass BA ba as a parameter to the method?

Sent from my HTC Desire Z
 

warwound

Expert
Licensed User
Longtime User
Ok here's my findings...


B4X:
public class MostBasicWindow extends StandOutWindow {
  // etc
}

B4X:
public abstract class StandOutWindow extends Service {
  // etc
}

So MostBasicWindow is a Service - and you've added it to the B4A manifest - can you create an instance of a Service in a B4A Activity?

B4X:
Sub Globals
   Dim RSStandOut1 As RSStandOut

   Dim RSMostBasicWindow1 As RSMostBasicWindow ' this is an instance of a Service

   Dim pnlBasic As Panel   
End Sub

Can you call a method of that Service before the Service has been started?

B4X:
Sub Activity_Create(FirstTime As Boolean)

   'Load activity stuff
   Activity.AddMenuItem("Show Basic", "mnuShowBasic")
   
   'Initialize RSStandOut1
   RSStandOut1.Initialize("RSStandOut1")
   
   'Initialize BasicWindow Panel
   RSMostBasicWindow1.Initialize("RSMostBasicWindow1") ' calling a method in a Service that has not yet been started
   pnlBasic.Initialize("BasicWindow")
   pnlBasic.LoadLayout("BasicWindow.bal")
   

End Sub

Lastly, look at the official Android demo Activity:

B4X:
public class StandOutExampleActivity extends Activity {
   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);

      StandOutWindow.closeAll(this, SimpleWindow.class);
      StandOutWindow.closeAll(this, MultiWindow.class);
      StandOutWindow.closeAll(this, WidgetsWindow.class);

      // show a MultiWindow, SimpleWindow

      StandOutWindow
            .show(this, SimpleWindow.class, StandOutWindow.DEFAULT_ID);
      StandOutWindow.show(this, MultiWindow.class, StandOutWindow.DEFAULT_ID);
      StandOutWindow.show(this, WidgetsWindow.class,
            StandOutWindow.DEFAULT_ID);

      // show a MostBasicWindow. It is commented out because it does not
      // support closing.

      /*
       * StandOutWindow.show(this, StandOutMostBasicWindow.class,
       * StandOutWindow.DEFAULT_ID);
       */

      finish();
   }
}

See finish() is called at the end of the onCreate()method?
The demo Activity starts the Service that displays the floating window and exits itself.

No Activity is running to interact with the floating windows, all floating window management is handled by the Service.

The Android permission android.permission.SYSTEM_ALERT_WINDOW is required, these floating windows are not normal Views that belong to any Activity.

Are you sure that a B4A project can interact with a system alert window?

Martin.
 

XverhelstX

Well-Known Member
Licensed User
Longtime User
Seems like this method is called before the Initialize method.

According to the official StandOut Activity:

B4X:
/**
     * Shows the most Basic Window.
     */
    public void showBasicWindow(MostBasicWindow mbw) {
        StandOutWindow.show(ba.context, mbw.getClass(), StandOutWindow.DEFAULT_ID);
    }

It seems that the class is passed (MostBasicWindow.class). I guess that would be the problem. (as initialized is not passed, so ba is not declared.) or is it what warwound is mentioning in the post above?

If mine, how would i be able to declare a ba instance?
B4X:
@Override
   protected void createAndAttachView(int id, FrameLayout frame) {
      Log.i("B4A", "View attached!");
      Log.i("B4A", "Eventname: " + this.eventName);
      if (ba==null) {
         Log.i("B4A", "BA Object is null");
      }
      Initialize(ba, "Eventname")
      ba.raiseEvent(null, eventName + "_createandattachview", new Object[] { id, frame } );

and i guess of the service thing, it declares the class, and not the instance itself. that's why i think ba is not declared, as the class was passed in the parameter

Tomas
}
 
Last edited:

warwound

Expert
Licensed User
Longtime User
Well MostBasicWindow is your Service class and you want that Service to contain a reference to an Activity BA object, so that it can raise events.

Is that possible?

Forget about the StandOut floating windows to start with.

Can you create an Android Service in Eclipse, add that Service to a B4A project, start the Service and pass it a reference to an Activity BA object?
Now can the Service raise an event or use one of the CallSubDelayed methods to interact with your B4A code, using that Activity BA object?

If you can do that then i think you'll have to apply the same logic to the sub-class of the StandOutWindow Service class.

Your sub-class of the StandOutWindow uses the (super-class) StandOutWindow static show() method to display a floating window.
From the StandOutWindow class:

B4X:
   /**
    * Show a new window corresponding to the id, or restore a previously hidden
    * window.
    * 
    * @param context
    *            A Context of the application package implementing this class.
    * @param cls
    *            The Service extending {@link StandOutWindow} that will be used
    *            to create and manage the window.
    * @param id
    *            The id representing this window. If the id exists, and the
    *            corresponding window was previously hidden, then that window
    *            will be restored.
    * 
    * @see #show(int)
    */
   public static void show(Context context,
         Class<? extends StandOutWindow> cls, int id) {
      context.startService(getShowIntent(context, cls, id));
   }


   /**
    * See {@link #show(Context, Class, int)}.
    * 
    * @param context
    *            A Context of the application package implementing this class.
    * @param cls
    *            The Service extending {@link StandOutWindow} that will be used
    *            to create and manage the window.
    * @param id
    *            The id representing this window. If the id exists, and the
    *            corresponding window was previously hidden, then that window
    *            will be restored.
    * @return An {@link Intent} to use with
    *         {@link Context#startService(Intent)}.
    */
   public static Intent getShowIntent(Context context,
         Class<? extends StandOutWindow> cls, int id) {
      boolean cached = isCached(id, cls);
      String action = cached ? ACTION_RESTORE : ACTION_SHOW;
      Uri uri = cached ? Uri.parse("standout://" + cls + '/' + id) : null;
      return new Intent(context, cls).putExtra("id", id).setAction(action)
            .setData(uri);
   }

The static show() method calls the static getShowIntent() method to create an Intent with which to start the sub-class of the StandOutWindow.

https://www.google.co.uk/search?q=java+override+static+method&ie=UTF-8&oe=UTF-8

You cannot override a static method it seems, otherwise i'd have suggested you override one or both of those static methods from the StandOutWindow super-class - i'm thinking that you could add the Activity BA object to the Intent that starts the sub-class and now your sub-class has a reference to the Activity BA object and can raise events or use the CallSubDelayed methods.

The basic problem is how to create a non-B4A Service in Eclipse, start that Service and pass it a reference to the Activity BA when all the methods used to start the service are static and not overrideable - you can't change behavior that starts the Service.

I think the answer is to modify the StandOutWindow super-class source (modify some of it's static methods) so that all sub-classes can now have the behaviour required for the B4A library - i'll be looking at the source code and will post again if i have any brainwaves lol!

Martin.
 

warwound

Expert
Licensed User
Longtime User
I just tried to get the demo MostBasicWindow to run - the TextView with Cyan background color...

Endless exceptions and i was about to give but decided to try it on my ICS Huawei Ascend.
The demo works perfectly!

Various exceptions and it never works on my CyanogenMod Gingerbread ZTE Blade.

What are you testing on Tomas?

Martin.
 
Top