Android :: Updating Activity From Asynchronous Service

Apr 2, 2010

I've implemented a service that does an asynchronous sync between my application and google docs. I want to update the top level activity of my application when the sync is complete. However because of the service it's possible that the app could be be in a unknown state. Is there a way to make the top level activity, whatever that may be, recreate itself from an asynchtask in a service.

Android :: updating activity from asynchronous service


Android :: Asynchronous Service Call While Starting Activity

Jul 24, 2010

I am starting an activity from one by passing some data in the intent. I want the next activity to call some asynchronous service (rest service) with the data from intent and show the result on screen.

View 1 Replies View Related

Android :: Service Updating Main Activity Gui

Aug 24, 2010

I have a service which collect data and send them to a certain URL and updating the main activity GUI, so which is better in the performance to use a long service with listeners to collect the data and threads in it to update the GUI and sends to the internet or to make another service responsible for updating the GUI and sending to the URL only while the first one just collects the data?

View 5 Replies View Related

Android :: MVC - Application Or Service For Asynchronous Updates

Jul 3, 2010

I have data that is to be refreshed from the Internet. Let's call it Model.

What I want to do: Basically it sounds like an MVC model, where the Model is also kept persistent in local (private) storage. The Model and its associated methods are application-wise. There are several Activity's that display and manipulate different aspects of it:

User
navigates across different Activity's
that display Model
from different perspectives. Currently I have a ListActivity for all elements, and an Activity for one element's details
Sometimes Model needs refreshing.
Surely this is done on a different thread. Refreshing can be triggered from several Activity's.
There are several (time consuming) common
tasks that can be triggered from different Activity's
My application loads and saves Model
to private storage when it starts
and stops

My problem: I'm not sure where to put Model and the related tasks in. Also, I don't know what mechanism to use to notify Activity's. Currently I come up with 2 approaches:

Use Service and send broadcasts. Saving to disk is performed in Service#onDestroyed(), so I want to minimize that by binding it to Activity's. At this point, I'm also not sure how to deliver the updated information: whether to provide a getter in Binder, or include that in the broadcast message.
Customize the Application object so that refreshing methods and getters are available globally. I then perform update from Activity's using AsyncTask. If there are other Activity's that are behind the current Activity, they will update in onResume() when the user navigates back.

Reasons I'm not using a class with static methods:

I need to save and store Model to disk. Some of the methods need a Context for displaying toasts, notifications, caching, etc.


Also, I don't put these functionalities in an Activity because there are several activities that manipulate the same piece of persistent data.

Below are pseudocode illustrating what I mean:

Using Service:

CODE:............

Make the functionality globally accessible in the custom Application object

CODE:...........

Weaknesses I can think of for the Service approach is complexity, since Binding is asynchronous. And it's very likely that I have to repeat some code because I have both ListActivity and Activity

For the Application approach, the documentation says not to rely on onTerminate() being called.

View 3 Replies View Related

Android :: Testing An Asynchronous Activity

Dec 2, 2009

I'm using a web service disguised as a ContentProvider and AsyncQueryHandler to isolate my activity from the delays of transport. My question is: during testing, how can I determine when my activity has retrieved the data from the web service? That would be after onQueryComplete() in the AsyncQueryHandler has come back with the "real" data. During manual testing, I just sit there and wait until the view updates. How can I do that using ActivityUnitTestCase and ActivityInstrumentationTestCase2?

View 2 Replies View Related

Android :: Kill Activity From Asynchronous Thread?

Sep 27, 2010

How can I kill Android activity from asynchronous thread? In my android application, I start another activity using startActivity. Is there anyway for me to kill that activity I started after several minutes?Or is there any way beside using thread?

View 2 Replies View Related

Android :: How To Access Droid Activity Stack From Asynchronous Thread?

Sep 26, 2010

There are a ton of activity stack related questions on StackOverflow, but I didn't really see any that answered the question I have. I'm working on an online game that (for now) has 3 different activities Login/Register Menu (seen when logged in, includes "new game", "my stats", and a few other things...I'm just worried about the "new game" option for now.

View 1 Replies View Related

Android :: Updating AppWidgetProvider From Service

Jan 1, 2010

Here is my issue, I want to be able to update a specific AppWidgetProvider (home screen widget) from a custom service class. I have to build the remote view in the service because I'm also doing some networking in there, which takes some time. The problem is that I can't figure out how to update a specific widget (individual widgets can have different update intervals, using the alarm manager). If I wanted to do it from the onUpdate of the AppWidgetProvider I could just call appWidgetManager.updateAppWidget(appWidgetId, remoteView); Does anyone have any experience with this or any suggestions?

View 4 Replies View Related

Android : Closing Activity Completely / Process Killed By Activity Manager Service

Aug 2, 2010

Whenever the memory needs to be reclaimed, the process is being killed by Activity Manager Service in killPidsForProcess. I have a back button in my activity window on right corner of the title bar.

I want to kill the activity completely on clicking the close button. Can I reuse the same function and will it have any major effect? Please help me out in this.

View 3 Replies View Related

Android :: Efficient Way Of Updating UI From Service Than Intents?

Apr 12, 2010

I currently have a Service in Android that is a sample VOIP client so it listens out for SIP messages and if it recieves one it starts up an Activity screen with UI components. Then the following SIP messages determine what the Activity is to display on the screen.
For example if its an incoming call it will display Answer or Reject or an outgoing call it will show a dialling screen. At the minute I use Intents to let the Activity know what state it should display. An example is as follows:

Intent i = new Intent();
i.setAction(SIPEngine.SIP_TRYING_INTENT);
i.putExtra("com.net.INCOMING", true);
sendBroadcast(i);
Intent x = new Intent();
x.setAction(CallManager.SIP_INCOMING_CALL_INTENT);
sendBroadcast(x);
Log.d("INTENT SENT", "INTENT SENT INCOMING CALL AFTER PROCESSINVITE");

So the activity will have a broadcast reciever registered for these intents and will switch its state according to the last intent it received...............

View 2 Replies View Related

Android :: Updating Information - Use Alarm / Service?

Jun 6, 2010

I am having some design techniques about How shall I schedule a code to retrieve the weather info? Should I use alarms to retrieve the weather each 10 minutes? And do I need to run a service for this? Or just put the code in the Broadcastreceiver and start when the alarm fired?

View 1 Replies View Related

Android :: Activity Check Service To Start Another Activity

Sep 10, 2010

I need to made an activity (without layout) that on start check if a service is running. if it is true it starts Activity2, if it false it starts Activity1.

I tried with this code:

CODE:............

Enter code here

But when I check, in the onCreate method, if serviceConnect!=null I receive sometime a NullPointerExcption.

I tried also to insert the operation in the method onCreate in an Async Task:

CODE:............

View 2 Replies View Related

Android :: Network Time Not Auto Updating With Some Service Provider?

Sep 9, 2010

I am facing problem in Froyo (Android 2.2), Network Time is not auto updating in date and time setting (using NITZ when Automatic option is enable) with some Service provider (Like BSNL and Reliance). but it's working fine with Vodaphone and Airtel. And i observe based on LOG statement that Unsoliciated Command UNSOL_NITZ_TIME_RECEIVED is not getting called at the time of Android system boot-up time with some Service Provider (like BSNL, Reliance) but it's getting called when i insert the Vodaphone and Airtel SIM card. but not able to figure out that How this UNSOL_NITZ_TIME_RECEIVED command has been triggered? If anybody have any idea please help me? Also i willing like to know where i have to made change, is it in Kernel level or Framework level?

View 3 Replies View Related

Android :: Best Practice On Updating UI From BroadcastReceiver To A Certain Activity?

Jul 18, 2010

When i have a broadcastReceiver say android.intent.action.MEDIA_BUTTON and i want to update the current activity's UI without creating a new activity, is there any good practice on this one?

What i know (might not be correct)

1) I can put the BroadcastReceiver in the same class as the activity and call the updateUI function after certain activity

2) Create a ContentObserver?

3) Communicate to a service created by the activity, use aidl. (I dont know how to get the current service if its registered from an activity)

4) Create a custom filter on the broadcastReceiver located on the same class as the activity, and use context.sendBroadcast(msg of custom filter) and in the custom filter call updateUI (same as one but more generic?)

The final flow is it would come from a BroadcastReceiver and ends up updating the UI without renewing the activity (unless the activity is dead?)

Kindly provide links/source code on your how you tackle this kind of problem.

View 1 Replies View Related

Android : Updating Chat Data UI From Different Activity Method?

May 4, 2010

I have a tab widget where one of the tabs is a chat-type feature. I want to update the chat data at an interval (variable depending on whether the chat tab is active or not).

The best approach seemed to be using an AsyncTask in my main TabActivity class, as that would avoid any issues of the chat activity being destroyed while in the background, while an AsyncTask was running. I wanted to ensure that the Activity isn't destroyed and recreated, thus causing my AsyncTask to be unable to modify the actual active Activity's data.

However, now that my AsyncTask is in the TabActivity activity, I don't have a direct way to call my Chat's ListAdapter notifyDataSetChanged() from my onPostExecute() method anymore. Is there a way to get a reference to a given Tab's current Activity from the TabHost/TabActivity?

Or, alternatively, can I assume my chat activity will never be destroyed as a child activity of the TabActivity activity (well, never destroyed while the TabActivity is active at least), and then just put the AsyncTask in the Chat Activity?

View 2 Replies View Related

Android :: Android - Updating TextView String Through AIDL Service

Aug 12, 2010

I have an app that uses a TabHost. Several of the Tabs share a common HUD. I am using a service to periodically update those values by calling an AIDL function when ready.

However, since several of the Tabs are using the same HUD I would like to abstract that part out.

I thought about having the HUD.xml use a String resource as it's value and then the abstracted class can update the String resource. However, apparently Android can not update String resources programatically.

The only alternative solution I see would be using SharedPreference.

I have concerns accessing a Database everytime the value is refreshed.

View 1 Replies View Related

Android :: Make Asynchronous URL Connections On Droid?

Sep 9, 2010

I am using the following class to connect to my web service. I would like to make this asynchronous. How can I do this? code...

View 1 Replies View Related

Android :: Asynchronous Sockets Implementation On Droid?

Sep 20, 2010

In iPhone there is Cocoa Asynchronous socket library. Is there a similar library in Java for Android? Can it be done using Java Asynchronous sockets(NIO library) or is there a way I can make use of NDK for Android and use native libraries for asynchronous sockets?

View 1 Replies View Related

Android :: How To Create An Asynchronous Communication Layer

Apr 13, 2010

I want to create a communication layer in android. The layer will communicate with server asynchronously. Multiple activities should be able to call methods of the communication layer. The layer will get messages from the server (it is not important for the scope of this question how) and should be able to tell activities to do some work based on these messages.

How should I implement this? Should I do this using android Service?

The main questions that I need to answer are: How can activities access the layer? How can the layer access activities? How can i make the communication layer live for the lifetime of the application?

View 4 Replies View Related

Android :: How To Stop Asynchronous Thread After 5 Seconds Of Running

Nov 24, 2010

Have to create thread and run it for 5 seconds, then I want to stop. How can I do that? I can't do anything with time/milliseconds.

View 3 Replies View Related

Android :: How Does A Service Communicate With Activity?

Feb 17, 2010

Suppose I have an Activity that's a list. It calls a Service when this Activity starts.The Service will do background stuff download, parse, and fill the list.My question is this: How can the Service communicate with the Activity?How can I call a method in the Activity, from the Service? (I'm new to OOP)

View 2 Replies View Related

Android :: Using Thread In Activity Or In Service?

Jun 12, 2010

In Virgil Dobjanschi's talk, "Developing Android REST client applications" (link here), he said a few things that took me by surprise. Including:
Don't run http queries in threads spawned by your activities. Instead, communicate with a service to do them, and store the information in a ContentProvider.
Use a ContentObserver to be notified of changes.
Always perform long running tasks in a Service, never in your Activity.
Stop your Service when you're done with it.

I understand that he was talking about a REST API, but I'm trying to make it fit with some other ideas I've had for apps. One of APIs I've been using uses long-polling for their chat interface. There is a loop http queries, most of which will time out. This means that, as long as the app hasn't been killed by the OS, or the user hasn't specifically turned off the chat feature, I'll never be done with the Service, and it will stay open forever. This seems less than optimal.

Long question short:
For a chat application that uses long polling to simulate push and immediate response, is it still best practice to use a Service to perform the HTTP queries, and store the information in a ContentProvider?

View 1 Replies View Related

Android :: Service Callback To Activity

Jan 13, 2010

Our application will expose a Service that can be called by Activities in other people's applications.In many cases, the parent applications calling Activity may be paused before our Service completes. I am looking for the best way for a Service to communicate back to the calling Activity that may have been paused.These are the known options:

(1) Require calling Activities to have a registerReceiver() with a custom action and broadcast to that from our Service. The only way to secure this registerReceiver() is with a signature-based permission.As our Service communicates with any number of unknown 3rd party apps,we can't sign our Service's parent app with all these unknown certificates. These apps would therefore be exposing an unsecured registerReceiver() on their Activity. Would ideally like to avoid requiring this.

(2) Create a PendingIntent to send results back to the activity and give it to our Service. Our Service would send data to calling Activity's onActivityResult(). Each time the result is delivered, the calling Activity will go through onPause() and onResume() but this should be OK.

(3) The calling Activities could create a Handler. The Activity would then create a Messenger pointing to that Handler and send it to our service. Our Service can then use the Messenger to deliver our message back to the calling Activity.

View 2 Replies View Related

Android :: Start Activity From The Service

Sep 3, 2010

I have a launcher activity which gets activated everytime i start the application and a service which complements it. Now as i press the return key from my main activity .Its Ondestroy gets called.Now i have nullify the pointer of the my launcher activity there. now i am listening through the service any event happening on the network after closing the launcher activity thread and if any event occurs i have to relaunch my launcher activity. i have tried intent but doesnot seems to get though it .

View 4 Replies View Related

Android :: Start An Activity From A Service

Oct 6, 2010

I have a service (input method) and from within that service I want to start and activity which was declared in the same manifest. The activity maybe running but in the background.

How do i check its presence and bring it to front, or optionally start this.

From what I can gather from other posts, this is about what I need to do:

CODE:..............

I don't knwo which of thest flags pertain to what I need to do. The docs are quite merky, and my random attempt at making this work failed.

View 4 Replies View Related

Android :: Start Service Without Using Any Activity

Oct 16, 2009

My application has a background process which continuously waits on a socket for receiving messages and it should be started only once and at the time of application starting.Thus i want to do that background job in a service.

The service should not be started from the activity ,it should be started at the application starting.

How can i define the service,which will be started at the time of application starting?

If at all the service is started from activity.The activity can be destroyed and restarted.when this happens the service also be restarted .

View 7 Replies View Related

Android :: How To Start Service From Activity?

Jun 14, 2010

How can I start a service from an Activity ?

View 4 Replies View Related

Android :: Start Service From Activity

Feb 25, 2010

In my app i have an activity from which i want to start an Service.

View 3 Replies View Related

Android :: Start Activity From Service

Aug 11, 2010

Is it possible to start an Activity from a Service? If yes, how can we achieve this?

View 1 Replies View Related

Android :: Calling Activity From Service

Nov 19, 2010

i am writing an app in which i need a background service to call an activity and show some result.

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved