When a web service call was invoked in BlackBerry, application hangs - java

I am creating my very first blackberry application that tries to connect to a rest web service. I tried the example I found in the internet. Please refer to this link: http://mobile-development.org/index.php/blackberry/how-to-call-restful-web-services-in-blackberry
I tried to implement it in my simple BlackBerry application which is the one that is automatically created when you create a new BlackBerry project in BlackBerry Plug-in for Eclipse IDE. I just placed the code (literally copied and pasted it) in my button, that when clicked, will execute such code. But, when I click the button, the application hangs.
When I implement a code that simply outputs "Hello" in the output log, the application works perfectly fine. What is the reason behind it? Do I need to run the web service call in a separate thread? Please help. Thank you in advance.
--------------------PLEASE READ BELOW----------------------
I noticed that my application hangs because it waits for a response from the web service call of at least 2 min. I read through this: http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800451/800563/What_Is_-_Different_ways_to_make_an_HTTP_or_socket_connection.html?nodeid=826935&vernum=0 -- and added "deviceside=true" at the end of the url (http://yourwebserviceurl.com;deviceside=true"). It works fine now. Maybe the proper implementation for this is to do the task in background or in a separate thread and set the timeout which I do not have a knowledge on it yet. I'm still confused on whether to set the deviceside to true/false. Should I set the deviceside to true when I'm running my app in a simulator then just change it to false if I want it to run in an actual device? That is for me to discover for now or you can help me out on this one as well. ;-)

The Code they have given is in for HTTP connection , It is totaly fine, But what we need to do call this code in a thread , because ui works also in thread by which by which it got stuck.
So you need to use thread concept here.
Look at Samples provided into
Eclipse helios\plugins\<sdk version>\components\samples\com\rim\samples\device\httpdemo
Whenever you wants to update UI In a background thread , use
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
<Update UI>
}
});
I hope it may help you .

Related

how to get correct exit code via java code from an spark app in cluster mode in kubernetes

I'm running a java spark app in cluster mode in kubernetes. At the moment I'm
using the SparkLauncher's java API to add a listener to get
notifications about the lifecycle from the running app. As far as I
understand the listener way is not fully implemented when running in
k8s. the code i'm using closes the spark context on the driver pod. this
results is state LOST in the java sparkapphandle.listener.
So my question is, which technically way should I use to get notified
about the state of the app I submitted. At the moment it is enough to
know the exit code of the app, not the progress or the state of every
executor.
I see the following tools
history server
rest api
task metrics
watcher api (https://github.com/kubernetes-client/java/blob/master/examples/src/main/java/io/kubernetes/client/examples/WatchExample.java)
I mean I see logs which contains infos i'm interested in. I believe it
is the class LoggingPodStatusWatcher.scala which logs these infos.
So can someone help me to point me to the smartest way to gather the
exit code programmatically from the app I started
thx
marko
My latest findings how to answer this questions, is to use the fabric8io library by using the wach api.
examples can be found here.
https://github.com/fabric8io/kubernetes-client/blob/master/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/PodTest.java

Service stopped when the app removes from recent apps list in android

In my application I am using service to run background services continuously even the app removes from recent apps list. But the service stopped if I remove the app from recent apps list. Can any one gives me the solution?
Thanks,
Sekhar
you have to make and show a notification until your service is running, use below code :
startForeground(id, notify.build());
for more information check example project in here .
or maybe your problem is like that .
good luck.
Start service by returning START_REDELIVER_INTENT onStartCommand of service to continuously run your service see my answer here.
And if you never have worked on service before then i suggest you to read Service documentation first so you will get more idea and clarification : refer this doc

Is it possible that the service still runs after the app got killed with task manager?

Hello im triying to run a service in background that it doesn't stop when app is destroyed by task manager. The idea of the service is verify every "x" min if there a new insert in a database that i got in a server.
The service is running great even if i close the app but when i use the task manager to destroy my app all the threads are closed too.
So i want to know if its possible to run a thread that ask in background forever unless user cancel it in the app itself, that ignore the destroy caused by task manager so in the future i can use notification bar to tell the user that a new insert happened in the database.
Tryed:
public int onStartCommand(Intent intent, int flags, int startId) {
// TODO Auto-generated method stub
askServer(); // i made a timertask that ask every "x" minute
return START_STICKY;
}
As i read START_STICKY should run again the service if it get killed for some reason and i know that this can be done since some app get closed by taskmanager and still get notifications from it as whatsapp,bbms and others. Please tell me if im wrong in anything and thank you for reading!.
UPDATE: Im not trying to break any law or security rule from Android and im not trying to ignore the stoping services option from an app in settings. I want that the service that listen for new incoming "events " inserts in my case keep running after user used the interface that appear when you press home for a while :
UPDATE : sorry for talking to much about this app but is the one that i can use as an example. In whatsapp when i close the app by the interface that i showed above the process and services are killed but after a couple of second they relaunch, this is exactly what i want to do to keep user informed about database events. From setting you still can stop the service without problem or even i can put the option in the app itself to stop notifiying.
Is a bad implementation call in OnDestroy() method an instance of the service so it relaunch after destroy?
UPDATE : welp looks like my service is still running on background after i close the app. I will just have to work on my service design to not waste battery life and resources. Also i was using the log.i() to check if service was running, looks like when main process closes i can't use log or toast just notifications ( still not implemented) because the service is there running just won't show in log .
UPDATE : now is working using using startForeground(0, null). In future i will send a notification to show when a event on database happen building it and calling startForeground(1, notification).
For services, look at Settings -> Applications -> Services. and see if it is running.
However, poorly designed services may run more often or perform syncing operations. So yes it is possible.
I had a problem similar to this when developing my first android game; force-stop was the only way to kill it.
START_NOT_STICKY will kill the background service when you swipe the app away from the task manager. START_STICKY is, as the name implies, "sticky", Meaning it sticks to the android system even when the app is gone.
That's from my experience, anyway.

How to call Android activity from a java servlet?

I am working on an android application, which is sends and gets data from MS SQL server via java servlets.
I need to update the UI of the application when Database has been updated.
I was thinking of implementing a looper class which will call a servlet via HTTP asyncTask, and call the servlet every few minutes. But it will be lots of work for the application and will slow down and also the UI needs to be updated as soon as the database has been updated.
Is there any way I can invoke the android application, from the servlet as soon as the Database has been updated? I cannot wait for the android application to make a call to servlet and check if database has been updated.
Any help would be greatly appreciated.
This is the first time I am writing a question on SO, please pardon my mistakes and suggest me how to improve.
Big thanks,
Ashley
A java servlet is stateless. This means that the connection is not maintained. The java servlet knows nothing of your application and cannot communicate directly with it.
If you must maintain the servlet setup then you can use Google Cloud Messaging to push the update to the user's phone. This is not exactly instantaneous though and there is a delay.
The thing that would work best for you is to change your java servlet into a java application that has a socket. You would then communicate with your java application via the socket and keep it open in a background thread. This thread will hold a callback to your activity which can populate it when a response is sent back over the thread to say data has been received.

How to debug an Android Background Service?

I have been developing a PhoneGap application for Android which contains a Background Service. My question is: How can I debug this service? Is it possible to debug using an AVD and go step by step? or can I use my own device to achieve that?
Thanks!
Yes, it can be done using AVD or device. Check out http://www.helloandroid.com/tutorials/how-debug-service and Debugging a service.
You can debug your service by putting a single statement , I am mentioning it here :
#Override
public void onCreate() {
super.onCreate();
//whatever else you have to to here...
android.os.Debug.waitForDebugger(); // this line is key
}
You can use your usual logs -for not in-depth debugging- inside the service and then use monitor tool to view those logs when the app is in the background or closed.
To open the monitor tool:
Open SDK( your SDK folder ) >tools>lib>monitor-x86_64
Open your monitor tool and select a device and you can view the loggings and search by tag as you do in your usual debugger.
Specific to intellij Idea, although there may be an equivalent solution for eclipse also,
I am adding a few more points to Shishupal's answer which worked for me, We need to add android.os.Debug.waitForDebugger(); in the service code.
But along with above, we need to uncheck "Deploy Application"
and select "Do not launch Activity".
In version 12.1.4 it looks like this:
Look for where your background service starts, for example
public BGcheckService() {
Log.d("BGcheckService: ", "starting service");
}
Then insert one line:
public BGcheckService() {
android.os.Debug.waitForDebugger();
Log.d("BGcheckService: ", "starting service");
}
Besides this, if your background service is in a separate process, then when you press the debug button to start debugging your background service, you also need to wait till the background service has started, then press the button to attach to process (see screenshot for Android Studio 3.6.1 .. it is the 3rd button to the right from the debug button). You will be given a choice of processes to attach to, one of which would be the background service's separate process.
NB:
Without the line android.os.Debug.waitForDebugger();, the background service would just start without waiting for the debugger to attach.
Even with the line android.os.Debug.waitForDebugger();, you still need to attach the debugger to the process of the background service.
The timing of when you press the button to attach to the process, needs to be after the background service has started (while it is waiting at android.os.Debug.waitForDebugger();), otherwise the process would not exist and you would not be able to select it.

Categories