deepstream.io-client-java icon indicating copy to clipboard operation
deepstream.io-client-java copied to clipboard

Android/Java client SDK : Blocks main thread for login error

Open irfaan008 opened this issue 8 years ago • 6 comments

I am using below code to login to deepstream

private static void loginToDeepStream() {
	try {
		client = new DeepstreamClient(Const.CONST_CHAT_HOST);
		client.setRuntimeErrorHandler(new DeepstreamRuntimeErrorHandler() {
			@Override
			public void onException(Topic topic, Event event, String s) {
				log("Error : via callback" + s);
				client.close();
			}
		});
		LoginResult result = client.login();
		if (result.loggedIn()) {
			log("realtime server ready");
		} else log("realtime server not ready");
	} catch (DeepstreamException ex) {
		log("error : " + ex.getStackTrace());
	} catch (URISyntaxException ex) {
		log("error : " + ex.getStackTrace());
	}
}

I tried to call this function from main thread and from background thread both, but whenever network goes offline, it calls setRuntimeErrorHandler and shows black screen on device (android). Seems it tries to reconnect again.

How can I force deepstream to make connections on background instead of main thread. Currently even I am calling this method from doInBackground method of AsyncTask class, it blocks UI when setRuntimeErrorHandler gets call .

Please assist me better way if any to perform login and reconnection code without blocking UI thread

irfaan008 avatar Jul 06 '17 21:07 irfaan008

Even i am Facing the same issue. is there any solution for this?

kirankiru avatar Oct 10 '17 13:10 kirankiru

Im terribly sorry about this, we have a few issues raised about threading.

We are generally going to do a small rewrite soon to reflect alot of lessons learnt and will introduce async methods to allow users to deal with threading themselves if desired.

yasserf avatar Oct 28 '17 17:10 yasserf

@yasserf It would be really good if this handling could be done easily at mobile end as mobile app loses network more frequently and those network exception must be handled internally at deepstream end. Along with that deepstream should also expose method to override the exception behaviour and should notify the activity/service of no network access

irfaan008 avatar Oct 29 '17 01:10 irfaan008

Same issue also for me, do you feel we are going to see a solution for this any time soon?

cdigiacinto avatar Oct 31 '17 07:10 cdigiacinto

Hey! We are working really hard to getting a new revamped JS and Java client out that addresses these problems. We will be looking at this next week and should have a beta out very soon.

yasserf avatar Nov 02 '17 15:11 yasserf

Thanks Yasser, for update. Let me know if I can help you in anyway. ᐧ

Irfan Raza mailTo: [email protected] New Delhi, India

On Thu, Nov 2, 2017 at 8:46 PM, Yasser Fadl [email protected] wrote:

Hey! We are working really hard to getting a new revamped JS and Java client out that addresses these problems. We will be looking at this next week and should have a beta out very soon.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/deepstreamIO/deepstream.io/issues/742#issuecomment-341454838, or mute the thread https://github.com/notifications/unsubscribe-auth/ADTJTsY_-nj0qR-yafaJJgC9eUZcEN9Jks5sydzYgaJpZM4OQNGp .

irfaan008 avatar Nov 02 '17 23:11 irfaan008