Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

BlackBerry Push Development

Reply
Regular Contributor
gunar_dev
Posts: 57
Registered: ‎09-22-2010
My Device: Not Specified
Accepted Solution

app frozen on background push

Hi,

 

I am implementing an application with Push feature for OS 5 and above and I have a problem: when the application is not running, when a message comes along, I am processing it (for the time being I am only logging some details) in a different thread, but when I am clicking the application icon the phone either freezes or the application is not opening at all - no log available from main(String[]) neither.

 

Below are some code snippets from the most important parts:

The base class for UIApplication:

public class JBBasePushApp extends UiApplication implements PushApplication {
	public void onStatusChange(PushApplicationStatus status) {
		// log the status code
	}
	
	public void onMessage(PushInputStream inputStream, StreamConnection conn) {
		printLog("#onMessage received ... cleaning up");
		new PushMessageHandler(inputStream, conn).start();
	}
}

 The implementation class:

public class CPUIApp extends JBBasePushApp {
	public CPUIApp() {
	}

	private void showUi() {
		MainScreen screen = new CPScreen(this);
		pushScreen(screen);
	}

	public static void main(String[] args) {
		CPUIApp app = new CPUIApp();
		if (app.isForeground() || app.isForegroundRequestInProgress()) {
			app.showUi();
		} else {
			app.printLog("Non gui call ...");
		}
		app.enterEventDispatcher();
	}

}

 and the PushMessageHandler class:

public class PushMessageHandler extends Thread {
	private static final String MESSAGE_ID_HEADER = "Push-Message-ID";
	private PushInputStream pushInputStream;
	private StreamConnection conn;
	private JSLogger logger;

	public PushMessageHandler(PushInputStream pushInputStream, StreamConnection conn) {
		appContext = ApplicationContext.getSingleInstance();
		logger = appContext.createLogger(getClass());
		this.pushInputStream = pushInputStream;
		this.conn = conn;
	}

	public void run() {
		try {
			HttpServerConnection httpConn = null;
			if (conn instanceof HttpServerConnection) {
				httpConn = (HttpServerConnection) conn;
			} else {
				logger.debug("Conn class: " + conn.getClass().getName());
				return;
			}
			String msgId = httpConn.getHeaderField(MESSAGE_ID_HEADER);
			String msgType = httpConn.getType();
			String encoding = httpConn.getEncoding();
			logger.debug("Msg props: id" + msgId + "; type: " + msgType + "; encoding: " + encoding);
		} catch (IOException e) {
			logger.error("run", e);
		} finally {
			cleanup(pushInputStream, conn);
			logger.debug("Done processing push message");
		}
	}

	protected void cleanup(InputStream is, Connection conn) {
		try {
			is.close();
		} catch (IOException ex) {

		}
		try {
			conn.close();
		} catch (IOException ex) {

		}
	}
}

 

If I am moving the call to enterEventDispatcher in the if() block then main() terminates its execution and it gives no chance for onMessage to execute ... After I am finishing the execution for onMessage triggered thread should I consider exiting somehow from event dispatcher - maybe calling requestClose()?

 

Any help would be highly appreciated!

 

 

Thanks,

gunar

Regular Contributor
gunar_dev
Posts: 57
Registered: ‎09-22-2010
My Device: Not Specified

Re: app frozen on background push

What I am doing there is stupind in main() .... showUi must always be called. Otherwise application enters in event dispatcher with no active screen and that is why it seems being blocked.