A webBrowser form crashes the app when backed - codenameone

When I press back button to go from a form with webBrowser component to any other form, it crashes in android. However, it works fine in iOS. Specifically it doesnt work in android samsung galaxy s5(android version 5.0) but works great in simulator and other android devices as well. I am updating the app. It worked great in previously built versions but is giving problem in new builds. I haven't changed anything in the form which makes it crash though.
I tried to debug the device and got following log. I think "Fatal signal 11 (SIGSEGV), code 1" is the main issue here
Log:
11-15 14:40:51.278: A/google-breakpad(9135): M A0598000 008F1000 007A1000 000000000000000000000000000000000 data#app#com.capitalEye.roundTable-1#base.apk#classes.dex
11-15 14:40:51.453: A/libc(8864): Fatal signal 11 (SIGSEGV), code 1, fault addr 0x0 in tid 8864 (lEye.roundTable)
11-15 14:40:53.653: E/audit(5364): type=1701 msg=audit(1479200153.653:335994): auid=4294967295 uid=10217 gid=10217 ses=4294967295 subj=u:r:untrusted_app:s0 pid=8864 comm="lEye.roundTable" reason="memory violation" sig=11
My code:
protected void beforeWebView(Form f) {
f.setLayout(new BorderLayout());
f.getToolbar().setUIID("Container");
t = new Toolbar();
t.setUIID("TitleAreaa");
f.setToolBar(t);
Style s = UIManager.getInstance().getComponentStyle("Button");
Image backtoRTN = FontImage.createMaterial(FontImage.MATERIAL_ARROW_BACK, s);
back = new Command("Back to RTN", backtoRTN) {
#Override
public void actionPerformed(ActionEvent evt) {
showForm("BusinessForum", this);
}
};
back.putClientProperty("uiid", "BacktoRTN");
f.setBackCommand(back);
t.addCommandToLeftBar(back);
}
#Override
protected void postWebView(Form f) {
if (Connectivity.isConnected()) {
WebBrowser wb = new WebBrowser();
if (businessWebsiteUrl != null && !businessWebsiteUrl.equals("")) {
wb.setURL("http://" + businessWebsiteUrl);
f.add(BorderLayout.CENTER, wb);
f.revalidate();
}
}
}

That's a system crash from the browser component which is a native peer. I'm guessing the underlying HTML triggered a bug in the webkit code of the native OS triggering that crash.
Since we use the native Android OS browser and VM a system level crash is an Android bug. We can workaround some of those but if it's within the HTML the likelihood of a workaround is slim.

Related

Casting error on android device and not on simulator

I see the following error from android tablet from log. Is there any issue in converting component to container in android?
As I wrote in the comments, I don't know why you have this casting error: because the class names in your log are obfuscated (by Proguard, that is used by default for Android), try to disable it temporarily to have a more readable log (I'm referring to the build hint android.enableProguard=false).
I have a lot of casting in my Codename One code. In general, for such cases, I use a code like the following:
Container myCnt = new Container();
myCnt.add(new Label("Test"));
myCnt.add(new Container());
for (Component cmp : myCnt.getChildrenAsList(true)) {
if (cmp instanceof Container) {
Container myChildCnt = (Container) cmp;
// do what I need with myChildCnt
} else {
Log.p("cmp is not a Container, it is: " + cmp, Log.WARNING);
}
}
The only notable difference with your code is the log to investigate the casting error. In this case, the log is:
[EDT] 0:0:0,76 - cmp is not a Container, it is: Label[x=0 y=0 width=0 height=0 name=null, text = Test, gap = 2]
Remember to try Android and iPhone skins in the Simulator to see if there are differences.

Codename One Geofencing

If you are experiencing an issue please mention the full platform your issue applies to:
IDE: NetBeans/Eclipse/IDEA
Desktop OS
Simulator
Device
If you are experiencing an issue please mention the full platform your issue applies to:
IDE: NetBeans
Desktop OS Ubuntu
Simulator Codeone Simulator
Device Galaxy Samsung 7
Using free service right now ( doing evaluation )
I am trying to implement geofencing which is the key part of development and don't have success so far , few questions and issues I am having and pls correct me if I am wrong
1) There is no support to test Geofence on simulator .I have to make the change make the build install on my device and test and when I do not see expected result I have no idea why it is failing and have to repeat the process
2) Now I am following the example
https://www.codenameone.com/javadoc/com/codename1/location/Geofence.html
I added a button with below action listener
{
Location loc = new Location();
loc.setLatitude(30.167043);
loc.setLongitude(-74.0059413);
Geofence gf = new Geofence("test", loc, 1999, 100000);
LocationManager.getLocationManager().addGeoFencing(GeofenceListenerImpl.class, gf);
});
I made sure by using fake gps itenary that I travel through this location on my device . When I click on the button Android ask permission to access the device location
public class GeofenceListenerImpl implements GeofenceListener {
#Override
public void onExit(String id) {
LocalNotification ln = new LocalNotification();
ln.setId("LnMessage1");
ln.setAlertTitle("Bye ");
ln.setAlertBody("Bye!");
Display.getInstance().scheduleLocalNotification(ln, System.currentTimeMillis() + 80 * 1000, LocalNotification.REPEAT_NONE);
}
#Override
public void onEntered(String id) {
System.out.println("com.mycompany.myapp.GeofenceListenerImpl.onEntered()");
if(Display.getInstance().isMinimized()) {
Display.getInstance().callSerially(() -> {
Dialog.show("Welcome", "Thanks for arriving", "OK", null);
});
} else {
LocalNotification ln = new LocalNotification();
ln.setId("LnMessage");
ln.setAlertTitle("Welcome");
ln.setAlertBody("Thanks for arriving!");
Display.getInstance().scheduleLocalNotification(ln, System.currentTimeMillis() + 80 * 1000, LocalNotification.REPEAT_NONE);
}
}
}
But the issue is I never see any notifications . Any help will be appreciated .
3) Do I need to minimize or close the app for geofence to work ( I have tried both and both don't work)
4) Is there any way to get the list of geofence being created ?
5) Any way to simulate the behavior on local simulator

WebBrowser issue (add infinite progress in web browser)

It takes a couple of seconds to load an url in webbrowser. Sometimes it takes more time to load. How to add infinite progress like that of connectionRequest in webbrowser?
#Override
protected void postWebView(Form f) {
WebBrowser wb = new WebBrowser();
if (businessWebsiteUrl != null && !businessWebsiteUrl.equals("")) {
wb.setURL("http://" + businessWebsiteUrl);
f.add(BorderLayout.CENTER, wb);
} else {
}
f.revalidate();
}
What I did but doesnot work
protected void beforeWebView(Form f) {
ip = new InfiniteProgress();
f.add(BorderLayout.CENTER, FlowLayout.encloseCenterMiddle(ip));
}
That's inherently problematic since a browser is effectively a peer component and while we can now paint on top of peers in Android this is still not portable.
Even if it would I'm not sure if it would be a good idea.
Overall you have the following options:
Place a progress indicator above/below the browser component
Fetch the data separately as HTML with a progress and set the HTML which should be instant
Use JavaScript and potentially an iframe to indicate progress from within the browser component itself

Application print function crashing in XP

I made a WPF application for family business which was working fine earlier. Last month they formatted the PC and this time installed XP. While the application still works, but it crashes as soon as an invoice or any other print action is taken.
Following is the code. Let me know any workaround this problem or I need to install Windows 7 again.
private void printButton_Click(object sender, RoutedEventArgs e)
{
string path = Directory.GetCurrentDirectory();
PrintInvoice pi = new PrintInvoice();
pi.DataContext = this.DataContext;
PrintDialog printDlg = new System.Windows.Controls.PrintDialog();
if (printDlg.ShowDialog() == true)
{
pi.Measure(new Size(printDlg.PrintableAreaWidth,
printDlg.PrintableAreaHeight));
pi.Arrange(new Rect(new Size(printDlg.PrintableAreaWidth, printDlg.PrintableAreaHeight)));
pi.Margin = new Thickness(40);
pi.UpdateLayout();
//now print the visual to printer to fit on the one page.
printDlg.PrintVisual(pi, "First Fit to Page WPF Print");
}
Directory.SetCurrentDirectory(path);
}
We have been experiencing a similar problem when some of our customers downgraded to Windows XP. In our case the exception message from the system Event Log was
Framework Version: v4.0.30319
Description: The application requested process termination through System.Environment.FailFast(string message).
Message: Unrecoverable system error
The solution was to install Microsoft XML Paper Specification Essentials Pack on the target machines.

What's causing my WP7 app to crash?

I've had a few unexplained crashes happening on both the emulator and the phone itself. Basically when my app crashes I get no dialog box whatsoever and the phone returns to the home screen.
I have the following code to display a MessageBox but this is somehow being bypassed...
// Code to execute if a navigation fails
private void RootFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)
{
MessageBox.Show(e.Exception.ToString());
}
// Code to execute on Unhandled Exceptions
private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{
MessageBox.Show(e.ExceptionObject.ToString());
}
The thought occurred to me that it might be related to memory, since my app deals with a lot of images. But I figure that would still be caught by my unhandled exception code above. Any ideas on how I should track this down would be appreciated.
Keep an eye on your memory usage. An OutOfMemoryException crashes your app without calling the Application_UnhandledException handler.
You can check the current memory usage with some built in methods. I blogged about this a while ago http://kodierer.blogspot.com/2010/09/windows-phone-memory-constraints.html
Here's the basic code you should add:
var timer = new DispatcherTimer {Interval = TimeSpan.FromSeconds(2)};
timer.Tick += (s, e) =>
{
var memuse = (long)DeviceExtendedProperties.GetValue("ApplicationPeakMemoryUsage");
var maxmem = (long)DeviceExtendedProperties.GetValue("DeviceTotalMemory");
memuse /= 1024 * 1024;
maxmem /= 1024 * 1024;
MyTextBlock.Text = String.Format("Mem usage: {0} / {1} MB", memuse, maxmem);
};
timer.Start();
A few things which have happened to me:
If you're doing things on other threads, then IIRC exceptions on those threads will cause the app to just terminate. You may want to wrap the new thread code in an exception handler which propagates the exception to the UI thread
If your app throws an exception before the first page is loaded, that can cause the app to just die without the appropriate handler being called
If you've got a StackOverflowException, that can't be caught and will just make the app bomb
You may want to add some debug-build-only persistent logging (loaded and displayed within the app itself) to make it easier to work out how far the previous run of the application had got before crashing.
My app crashed in exactly the same way.
I tracked it down to throwing an OutOfMemoryException inside a DispatcherTimer tick handler, though the problem probably occurs elsewhere as well.
However, it is not the case that an OutOfMemoryException always takes down your program. It does not. I tried it in various other handlers, and it was correctly caught.
I've posted a blog entry about lost exceptions here
Could your app be being watchdoged for being unresponsive for too long? Perhaps due to the load time of lots of images and this code being executed on the UI thread.

Resources