patternjavaMinor
Making a lightweight app in BlackBerry Browserfield
Viewed 0 times
applightweightbrowserfieldmakingblackberry
Problem
This is an app made by me to display a web page on blackberry and to add some more features like checking network connectivity while opening app, loading some URL in browser rather than app, making a splash screen and loading animation.
The problem with the code is that when I run this app on blackberry device it after some time says "low memory on device. Please close some app" and this will close my app. I understand that this is a problem of browserfield as shown in this thread. However I wish to make this code lightweight. This means none of the above features need to be compromised, but the amount of memory needed by the app need to be reduced so that app does not consume that much memory that it needed to be closed. I think above details are sufficient perhaps. I am ready to give further details as asked. this whole app was designed by me using Blackberry Eclipse plugin.
Can someone review this and suggest ways of making it lightweight?
MyApp.java
MyScreen.java
```
public final class MyScreen extends MainScreen
{
protected static boolean pageLoaded = false;
private BrowserField browserField;
private VerticalFieldManager mainManager;
private String targetURL = "http://reelafrica.net";
public MyScreen()
{
createGUI();
}
private void createGUI()
{
mainManager = new VerticalFieldManager(Field.USE_ALL_WIDTH | Field.USE_ALL_HEIGHT | Manager.VERTICAL_SCROLLBAR | Manager.HORIZONTAL_SCROLLBAR );
browserField = new BrowserField();
The problem with the code is that when I run this app on blackberry device it after some time says "low memory on device. Please close some app" and this will close my app. I understand that this is a problem of browserfield as shown in this thread. However I wish to make this code lightweight. This means none of the above features need to be compromised, but the amount of memory needed by the app need to be reduced so that app does not consume that much memory that it needed to be closed. I think above details are sufficient perhaps. I am ready to give further details as asked. this whole app was designed by me using Blackberry Eclipse plugin.
Can someone review this and suggest ways of making it lightweight?
MyApp.java
public class MyApp extends UiApplication
{
public static void main(String[] args)
{
// Create a new instance of the application and make the currently
// running thread the application's event dispatch thread.
MyApp theApp = new MyApp();
theApp.enterEventDispatcher();
}
public MyApp()
{
// Push a screen onto the UI stack for rendering.
extracted();
pushScreen(new SplashScreen());
}
private void extracted() {
new ApplicationPermissions().addPermission(ApplicationPermissions.PERMISSION_INTERNET);
}
}MyScreen.java
```
public final class MyScreen extends MainScreen
{
protected static boolean pageLoaded = false;
private BrowserField browserField;
private VerticalFieldManager mainManager;
private String targetURL = "http://reelafrica.net";
public MyScreen()
{
createGUI();
}
private void createGUI()
{
mainManager = new VerticalFieldManager(Field.USE_ALL_WIDTH | Field.USE_ALL_HEIGHT | Manager.VERTICAL_SCROLLBAR | Manager.HORIZONTAL_SCROLLBAR );
browserField = new BrowserField();
Solution
You should fix your indentation. I want to review the code, but a lack of indentation makes it really hard to read it.
You use Eclipse, so use this to format your code:
Ctrl + Shift + F
Or, in the main menu > Source > Format
Aside from that, there's a couple small things I see:
You're indenting your comments.
To me, this is bad practice. I've been bitten by it before;
Someone writes a long line of code...
And you miss the important stuff because you miss the last bit of the comment due to unfortunate sentence endings.
Don't indent your comments, and if you have a long comment put it on a separate line. I recommend putting it before the code, that's where javadoc comment blocks go anyway.
You put spaces after variables.
Specifically,
and
. To me, these disrupt my ability to identify what a word means. A space acts as a separator of "things" to me. And if you put a space between a function name and the arguments then I have to read it twice to understand what's going on.
You use Eclipse, so use this to format your code:
Ctrl + Shift + F
Or, in the main menu > Source > Format
Aside from that, there's a couple small things I see:
private int _totalFrames; //The total number of frames in the image.
private int _loopCount; //The number of times the animation has looped (completed).
private int _totalLoops; //The number of times the animation should loop (set in the image).You're indenting your comments.
To me, this is bad practice. I've been bitten by it before;
Someone writes a long line of code...
public static Object spliceIndex(List objects, int index){//Removes object from list. IMPORTANT: This function is 1-indexed!And you miss the important stuff because you miss the last bit of the comment due to unfortunate sentence endings.
Don't indent your comments, and if you have a long comment put it on a separate line. I recommend putting it before the code, that's where javadoc comment blocks go anyway.
You put spaces after variables.
Specifically,
add (new BitmapField(obj));and
this. setBackground(bg);. To me, these disrupt my ability to identify what a word means. A space acts as a separator of "things" to me. And if you put a space between a function name and the arguments then I have to read it twice to understand what's going on.
Code Snippets
private int _totalFrames; //The total number of frames in the image.
private int _loopCount; //The number of times the animation has looped (completed).
private int _totalLoops; //The number of times the animation should loop (set in the image).public static Object spliceIndex(List<Object> objects, int index){//Removes object from list. IMPORTANT: This function is 1-indexed!add (new BitmapField(obj));this. setBackground(bg);Context
StackExchange Code Review Q#57678, answer score: 5
Revisions (0)
No revisions yet.