Android Question Daydream Service. Any way to use LoadLayout or StartActivity?

Jerez

Active Member
Licensed User
Longtime User
Hello,

I have tried the Daydream tutorial on Android TV 6. About 3 years old and still work.

But anyway to use
B4X:
dd.Panel.LoadLayout("Layout1")
without app crashes?

Please help.

https://www.b4x.com/android/forum/threads/android-daydream-dreamservice-tutorial.24939/

This is crash log:

B4X:
Installing file.
PackageAdded: package:com.b4aExample.daydream
** Service (dreamservice) Create **
** Service (dreamservice) Start **
onDetachedFromWindow
** Service (dreamservice) Start **
Error occurred on line: 27 (DreamService)
java.lang.RuntimeException: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Class java.lang.Object.getClass()' on a null object reference
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:166)
    at anywheresoftware.b4a.objects.PanelWrapper.LoadLayout(PanelWrapper.java:134)
    at com.b4aExample.daydream.dreamservice._dd_sizechanged(dreamservice.java:170)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:708)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:340)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
    at anywheresoftware.b4a.BA$1.run(BA.java:293)
    at android.os.Handler.handleCallback(Handler.java:751)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6077)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Class java.lang.Object.getClass()' on a null object reference
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayoutHelper(LayoutBuilder.java:394)
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayoutHelper(LayoutBuilder.java:425)
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:144)
    ... 16 more
** Service (dreamservice) Destroy **

Thanks very much.
 
Last edited:

Jerez

Active Member
Licensed User
Longtime User
Last edited:
Upvote 0

Jerez

Active Member
Licensed User
Longtime User
You can start an activity by calling StartActivity(...).

After start an Activity a black screen appears in front (dd service). When I press the back button on my remote dd is gone and Activity is there. If I finish the dd after start the Activity the TV signal is gone.
 
Upvote 0

Jerez

Active Member
Licensed User
Longtime User
Which tv signal?
I'm using a Nexus Player with Android TV that uses HDMI-CEC. When I finish the dd service (dd.Finish) the HDMI signal is gone. I need to unplug the HDMI cable and connect it again to restore the signal. This occurs only if I start an Activity and later finish the dd.

I'm adding controls with code like webview example and problem solved. I'm looking for a code for image transition that work with dd.

I've tried to add a MediaPlayerStream but does not work:

B4X:
    mp.Load("http://www.quirksmode.org/html5/videos/big_buck_bunny.mp4")
  
    pnl.AddView(mp, 0dip, 0dip, dd.Panel.Width, dd.Panel.Height)

B4X:
B4A version: 6.30
Parsing code.    (0.01s)
Compiling code.    (0.05s)
Compiling layouts code.    (0.00s)
Organizing libraries.    (0.00s)
Generating R file.    (0.05s)
Compiling debugger engine code.    (0.90s)
Compiling generated Java code.    Error
B4A line: 71
pnl.AddView(mp, 0dip, 0dip, dd.Panel.Width, dd.Pa
javac 1.8.0_101
src\com\ownapp\daydream\dreamservice.java:217: error: incompatible types: MediaPlayerStreamWrapper cannot be converted to View
_pnl.AddView((android.view.View)(_mp),anywheresoftware.b4a.keywords.Common.DipToCurrent((int) (0)),anywheresoftware.b4a.keywords.Common.DipToCurrent((int) (0)),_dd.getPanel().getWidth(),_dd.getPanel().getHeight());
                                ^



The Code:


B4X:
Sub dd_SizeChanged

    Dim pnl As Panel
    pnl.Initialize("pnl")
   
    pnl.Color = Colors.Black
       
    Dim lblTime, lblDate As Label
   
    'Date
    DateTime.DateFormat = "EEEE, d MMMM"
    DateTime.TimeFormat = "HH:mm"
   
    lblDate.Initialize("lblDate")
    lblDate.Text = DateTime.Date(DateTime.Now)
    lblDate.TextSize = 30
   
    pnl.AddView(lblDate, 50dip, dd.Panel.Height - 100dip, 500dip, 100dip)
   
    'Time:
    lblTime.Initialize("lblTime")
    lblTime.Text = DateTime.Time(DateTime.Now)
    lblTime.TextSize = 48
   
    pnl.AddView(lblTime, 50dip, dd.Panel.Height - 160dip, 500dip, 100dip)
   
   
    'Video
   
    mp.Initialize("mp")
   
    mp.Load("http://www.quirksmode.org/html5/videos/big_buck_bunny.mp4") 
   
    pnl.AddView(mp, 0dip, 0dip, dd.Panel.Width, dd.Panel.Height)
   
   
    dd.Panel.AddView(pnl, 0dip, 0dip, dd.Panel.Width, dd.Panel.Height)

End Sub
 
Last edited:
Upvote 0
Top