Closing an application programmatically with custom error message? - java

I want to close my Android application with a method, but it should be shown a custom message (which I define for myself).
everything I found yet was "How to close my application" and I got more than 10 ways to close my application but I haven't found a way to set a custom message.
At the moment if my app crashes something like this appears:
[APPNAME] has been stopped
I want something like this
Congratulations! You found a bug, please submit it.
Is there even a way to do that? All methods I found just closed all activities or just forced an unresolveable error.
I don't think you need some code from me, but if you do, tell me.
(Language should be java and javascript/jQuery should be avoided)

You could try making a static stop method:
public static void stop(String message) {
Log.d(message);
System.exit(0);
}

Related

How to handle Call during crash?

I'm working on a phone-conference app on Android 7. I found this problem.
When app crash I loose ongoing call control resulting in app closed and voice channel open.
Reopening app result in two ongoing calls.
There are ways to close the first voice call?
I try closing the call at app restart but obviously Android OS don't let me touch it.
the best (still not working) result I achieved is error class extension. that event is fired at crash start.
here is my class CrashKillCall that implements Thread.UncaughtExceptionHandler
public void uncaughtException(Thread t, Throwable e) {
//"the last song kill the audience" by Crash & the boys
Log.e(TAG, "--------------------------------------");
Log.e(TAG,t.getName());
Log.e(TAG,e.getCause().getMessage());
Log.e(TAG, "--------------------------------------");
crashCall.disconnect();
Log.e(TAG,"work?");
}
public static void setCall(Call call){
crashCall=call;
}
the desired result is some way to, or to let system know that i want to, terminate the ongoing or all calls.
thank you for your help.
ended out that i was pointing at wrong Call object. code work, you just need declare an istance of that class as default exception listener and register the right Call

Custom Internal Server Error Message Play Framework

In play framework, every time you get an Internal Server Error (500) in production mode, the browser shows a web page with
Oops, an error occured, This exception has been logged with id XXXX
I would like to customize the error message (or at least translate it to spanish), keeping the error id that makes it easier to look for in the application log.
I've tried to configure an error page in the Global settings in JAVA like this:
public Promise<Result> onError(RequestHeader request, Throwable t) {
return Promise.<Result>pure(internalServerError(
views.html.error.render(t)
));
}
Where I've a view named error.scala.html.
It is not working right now, it does not show any errors, just ignores it. Also with this alternative, I don't know how to display the error id.
I appreciate any suggestions, thanks a lot.
Is your Global class in the root package? That's a quite common mistake and also the reason why it is ignored.

execute javascript code in an android.webkit.WebView without loadUrl or XHR

I am writing a phoneGap plugin to allow multitouch on android devices (hoping to get this included in phonegap/callback eventually)
Event delegation is taking ~200ms using the plugin success callback and ~50ms with the WebView.loadUrl('javascript:somecodehere()') call
Unfortunately loadUrl has the side-effect of flickering the soft keyboard which isn't acceptable for a general solution.
Phonegap's Plugin.success uses an internal web server and an XmlHttpRequest object to send data, this method is way too slow.
Is there any 3rd method of sending javascript to the web browser? (or even sending a poke to the javascript engine to cause an event to happen, so that event could check a custom jsInterface object)
Take a look at addJavascriptInterface in the WebView class. It sounds more like what you are looking for.
In you plugin try calling:
this.ctx.sendJavascript(statement);
Not quite as fast as loadUrl but it may be a bit faster than returning a PluginResult.
You could roll your own stripped down message queue with a java object that is basically an arraylist and an accessor, then use addJavascriptInterface to bind it into the javascript context and inject a javascript polling loop that uses setTimeout to call the accessor method of your queue. Whenever you have javascript to execute, just add it to your arraylist. I'm not sure how it would perform, but perhaps it's worth a try?
class JSQueue {
private ArrayList<String> messages;
public String getMessage() {
String message = "";
if(messages.size() >0) {
message = messages.remove(0);
}
return message;
}
public void addMessage(String message) {
messages.add(message);
}
}
JSQueue jsq = new JSQueue();
dc.appMobiCanvas.hiddenView.addJavascriptInterface(jsq, "jsq");
dc.appMobiCanvas.hiddenView.loadUrl("javascript:(function checkJSQ(){eval(jsq.getMessage());setTimeout(checkJSQ, 50);}})();");
//add messages via jsq.addMessage();
It seems we have developed something similar
https://github.com/Philzen/webview-multitouch-polyfill
However, i have never experienced the issue you're describing before, but maybe you would like to test on your device or maybe contribute your expertise to the project. It has already been suggested on the Cordova (Phonegap) Roadmap, so we'll happy about every user and/or contributor to help this cause!

OtpNode triggering IOException

I experience a strange problem. Sometimes our Java app will not start and will raise an IOException when trying to open a OtpNode. Here is the code (really nothing special):
OtpNode oNode = new OtpNode(NODE);
oNode.setCookie(COOKIE);
OtpMbox mbox = oNode.createMbox(MBOX);
NODE, COOKIE and MBOX are hardcoded constants. The error I get is:
class java.io.IOException,
'Nameserver not responding on Martin-PC when publishing jnode',
Stack trace: [Ljava.lang.StackTraceElement;#c3ea5a
That's it. And this happens only sometimes. I observed that when restarting the PC it happens.
Had anyone seen similar problem?
Thank you.
It turned out that after restrat the Erlang virtual machine sometimes is not running. So we need to start it first before Java OtpNode could be started:
erl -sname whatever
http://www.erlang.org/doc/man/erl.html

changing unloadConfirmation message for modal windows in Apache Wicket

If you close the window when using ModalWindows in wicket, you get this message:
"Reloading this page will cause modal window to disappear"
Is there a way to configure this to show OTHER message? (for i18n purposes)
Thanks a lot!!
Manuel
You can dismiss the modal window message by setting the Javascript variable Wicket.Window.unloadConfirmation to false and provide your own handler on window.onbeforeunload.
So you have to set the following Javascript in your pages :
Wicket.Window.unloadConfirmation = false;
window.onbeforeunload=function(){
return I18n("yourI18nKey");
}
That is a browser dependent message and not a wicket message.
I believe Chrome and IE will show the one you pointed out.
Firefox 4 shows "This page is asking you to confirm that you want to leave - data you have entered may not be saved.".
I found out another, quite common way to get that warning when developing a modal view: if you happen to get this confirmation box by accident, it may be an indication of error in your code (Exception on log) and fixing the error also fixes the show of this message.
Good to note is that the confirm box is only an indication of error, not the cause of error itself. The error is elsewhere.
Source: http://ttlnews.blogspot.fi/2010/07/lessons-learned-wicket-spring-hibernate.html

Categories

Resources