Using the Java function to call alertDialog?

306 views
Skip to first unread message

Chad Wolf

unread,
Dec 25, 2014, 11:01:43 AM12/25/14
to tas...@googlegroups.com
I'm really terrible at making scenes look just right and I'd like them to match the os even across devices.

Pent

unread,
Dec 25, 2014, 12:45:47 PM12/25/14
to tas...@googlegroups.com
What is 'alertDialog' ?

Pent

Chad Wolf

unread,
Dec 25, 2014, 12:49:38 PM12/25/14
to tas...@googlegroups.com

Pent

unread,
Dec 26, 2014, 4:13:22 AM12/26/14
to tas...@googlegroups.com
Might work, if you know Java go ahead and try.

Pent

Chad Wolf

unread,
Dec 26, 2014, 4:26:16 PM12/26/14
to tas...@googlegroups.com
(AlertDialog.Builder) alertDialogBuilder = new AlertDialog.Builder(CONTEXT)

It says function invalid value. I've tried with and without casting and with and without parentheses.

Any ideas?

Chad Wolf

unread,
Dec 27, 2014, 4:50:23 PM12/27/14
to tas...@googlegroups.com
I finally got the syntax right but tasker doesn't appear to have AlertDialog.Builder implemented.

Pent

unread,
Dec 28, 2014, 3:19:43 AM12/28/14
to tas...@googlegroups.com


I finally got the syntax right but tasker doesn't appear to have AlertDialog.Builder implemented.

Sorry, was going to respond yesterday but wanted to try to answer your original question first.

There's a bug with inner classes (like AlertDialog.Builder) that makes selection and execution
of functions impossible (for instance, you should be able to specify AlertDialog.Builder as
the class and then select the 'new' function with the function selector).

Will fix for next version of course.

Pent

Pent

unread,
Dec 28, 2014, 3:38:08 AM12/28/14
to tas...@googlegroups.com


Sorry, was going to respond yesterday but wanted to try to answer your original question first.


The answer is unfortunately that you can't because a dialog needs an activity context to show over,
whereas the CONTEXT you get from Tasker is an application context (based on a service).

Possibly in the future I could add the option to run in an activity context...

Pent

David Wang

unread,
Jan 6, 2015, 4:02:23 AM1/6/15
to tas...@googlegroups.com
The answer is unfortunately that you can't because a dialog needs an activity context to show over,
whereas the CONTEXT you get from Tasker is an application context (based on a service).

A system-wide dialog can be made from a service context.  Refer here and StackOverflow.

I made a test using Java Function in Tasker. But I got error in Step-4 of my tasks. Didn't know why(a bug or something ?). Xml file attached.

And I find that most developers created a foremost floating window with "WindowManager.LayoutParams.TYPE_SYSTEM_ALERT" feature of AlertDialog. These floating window can be dragged and moved by finger as you wish. I know creatures of scenes in Tasker cannot be dragged freely. Maybe you could try the special feature of AlertDialog to improve scene in Tasker. Refer here.




AlertDialog.tsk.xml

David Wang

unread,
Jan 8, 2015, 12:24:01 AM1/8/15
to tas...@googlegroups.com
The logcat only shows error:
01-08 13:13:04.520 W/Tasker  (2100): 13.13.04#E: warning: Java Function: java.lang.reflect.InvocationTargetException

The "java.lang.reflect.InvocationTargetException" error is same as my previous task.

No enough information revealed. 
 

Pent

unread,
Jan 8, 2015, 10:32:09 AM1/8/15
to tas...@googlegroups.com
In the system log is:

D/Tasker  ( 1103): 16.27.09#E: targetClass: class android.app.AlertDialog$Builder
D/Tasker  ( 1103): 16.27.09#E: object: android.app.AlertDialog$Builder@acdb7f9
D/Tasker  ( 1103): 16.27.09#E: method: public android.app.AlertDialog android.app.AlertDialog$Builder.create()
D/Tasker  ( 1103): 16.27.09#E: argObjects: zero-length
W/Tasker  ( 1103): 16.27.09#E: warning: Java Function: java.lang.reflect.InvocationTargetException
D/Tasker  ( 1103): 16.27.09#: Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
D/Tasker  ( 1103): 16.27.09#: android.os.Handler.<init>(Handler.java:200)
D/Tasker  ( 1103): 16.27.09#: android.os.Handler.<init>(Handler.java:114)
D/Tasker  ( 1103): 16.27.09#: android.app.Dialog.<init>(Dialog.java:108)
D/Tasker  ( 1103): 16.27.09#: android.app.AlertDialog.<init>(AlertDialog.java:125)
D/Tasker  ( 1103): 16.27.09#: android.app.AlertDialog$Builder.create(AlertDialog.java:967)

One of my favourite Android complaints :-)

It's because Tasker tasks do not run on the UI thread. You can just do Looper.prepare(), but no
idea if that has other consequences for Tasker in general.

In any case, if Looper.prepare() is added, your digbuilder.show() function gives:

W/WindowManager(  745): Attempted to add application window with unknown token null.  Aborting.
W/Tasker  ( 1103): 16.29.26#E: warning: Java Function: java.lang.reflect.InvocationTargetException
D/Tasker  ( 1103): 16.29.26#: Caused by: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?
D/Tasker  ( 1103): 16.29.26#: android.view.ViewRootImpl.setView(ViewRootImpl.java:562)
D/Tasker  ( 1103): 16.29.26#: android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:272)
D/Tasker  ( 1103): 16.29.26#: android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
D/Tasker  ( 1103): 16.29.26#: android.app.Dialog.show(Dialog.java:298)
D/Tasker  ( 1103): 16.29.26#: android.app.AlertDialog$Builder.show(AlertDialog.java:987)
D/Tasker  ( 1103): 16.29.26#: java.lang.reflect.Method.invoke(Native Method)

Which I guess is because the builder is being called with an application context rather than an activity context.

Pent
Reply all
Reply to author
Forward
0 new messages