Show/Hide Toolbars

Android Applications

Toast Messages From Androidapi.JNI.Widget allow you to Pop up short messages of limited duration in the the UI.

 

       TJToast.JavaClass.makeText(TAndroidHelper.Context, StrToJCharSequence(ToastText), TJToast.JavaClass.LENGTH_LONG).show;

 

Very useful to post stuff (Progress) to the UI but there are limitations depending on the thread under execution.

A No Looper Thread error occurs in some cases.

 

Error>>

'java.lang.NullPointerException: Can'''t toast on a thread that has not called Looper.prepare()'

Looper is missing in TThread.Create

 

Work Around One

When I first encountered this error I used my limited thread to set a variable and then a refresh timer to throw the Toast message as a work around.

 

Work Around Two - A Toast Publishing Service

While A TTimer Event in Sydney supports Looper it does not in Berlin so for those projects I developed an external "Echo" Service which returns any text sent via a message handler which in turn supports Toast.

 

That Service is published on GitHub as libRemoteEchoService.so  and an additional object in the DM unit supports a class function

 

class function TToastViaEchoObj.ToastMsgViaEcho(AMessage: String; AErrorProc:TErrorProc=nil): TToastViaEchoObj;

 

Using that service to post Toast Messages. You can get access to the Echo Service by either

Installing RemoteEchoHostApp on your device or

By including the RemoteEchoService in your application package and adding the line  SvcEchoDM.SVCEchoPackageName:='com.embarcadero.MyApplicationName'; to the .dpr code before Application.run.