Android :: Use An Activity Or A Service When Using A Button In A Widget?

Aug 9, 2010

I have made a Android Widget which displays two articles (title + image). In addition to this, I have buttons for flipping backward and forward through the articles. What I don't understand is how I can change the Widgets RemoteViews when the buttons are pressed. Which should be one of the most basic operations in a widget, however, I can't seem to figure it out.

So... Can I do this with just a OnClickListener in the AppWidgetProvider? Or do I have to create an Activity without a window (visibility = false)?

Android :: use an Activity or a Service when using a button in a Widget?


Android :: Button Click Does Not Start Service In App Widget

May 31, 2010

I'm having trouble starting a Service to update an AppWidget that I'm creating as an exercise. I'm trying to get the latitude and longitude of spoofed location data from DDMS to display in the widget. The widget uses a service to update the TextView, which may be slightly overkill, but I wanted to follow the template that seems to be common in AppWidgets that do more work (like the Forecast widget or the Wiktionary widget).

Right now, I'm not getting any error messages or strange behavior; nothing at all happens when the button is pressed. I'm a bit mystified as to what might be wrong. Could anyone out there point me in the right direction?

Additionally, if my logic for location is faulty, I'd love recommendations on that too. I've looked at several blogs, the Google examples, and the documentation, but I feel a little fuzzy on how it works.

Here is the current state of the widget:

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

View 1 Replies View Related

Android :: Widget Starting Service Also Starts Main Activity

May 3, 2010

I have a widget that is supposed to start and stop a service (start it when it's not running, stop it when it is). This is working fine, however, each time the service is started, my app's main activity is also launched, which I don't want from the app's manifest, it works as I want it to (without launching the main-activity, just the service), but then I obviously don't have a main activity anymore.This is how I start the service (I would assume this is the normal way, and I can't see any reference to what might cause the MAIN intent to fire).

View 1 Replies View Related

Android :: Activity Which Downloads Data In Background With Service - Doesn't Get Destroyed On Hitting Back Button

Nov 9, 2010

I need to develop an application with downloads the data at the background and update about the progress in the front.

I guess this can be achieved using services and activity and passing data in between the. But, what I need to do is even if I hit back button and then start the activity again. It should check if the service is running or not. If service is not running it should start one else it should display the data from running service.

Something like music player where music is played by a service at a background and activity displays the information. Even on browsing through other activities of the application or hitting back, state of the music player is maintained.

View 1 Replies View Related

Android :: Launch The Same Activity From Widget With Different Extras - Prevent Same Instance Show Up After Returned From HOME Button?

Nov 5, 2010

I have a widget that contains 4 buttons to show 4 stock prices, each of them will launch into the same activity Quote.class to show stock details. In onUpdate(), it will set up the pendingIntent with extras with stock symbol. After I hit button A, it goes to Quote activity that shows stock A. Then I hit the BACK button to the homescreen, Quote activity calls onDestroy() and when I hit button B, stock B will show properly. However, when i hit HOME button after it shows stock A, the Quote activity only calls onStop without calling onDestroy(), then as i hit button B, it will call onStart() and it shows the same instance that shows stock A.

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

Originally I thought adding a flag in the Intent should solve this problem. But I have tried
i.setFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK or FLAG_ACTIVITY_NEW_TASK or FLAG_ACTIVITY_NO_HISTORY), none of them makes any difference.

So is there any ways to make it work? How can i remove the history stack from HOME button? How can I call onCreate in Quote activity and get new extras when i hit button B?

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 :: 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 :: How To Control Activity Flow - Back Button Versus Home Button

Sep 2, 2010

I have 3 activities in my app: Activity1 -> Activity2 -> Activity3. Inside Activity3, if the user presses Back, I would like to return to Activity2. In Activity3's onPause event, I added a finish() statement. That's probably not even necessary, but I wanted to make sure this Activity gets cleaned up. This works fine.
However, while in Activity3, if the user presses Home or starts a new app (through notification bar or some other means), I want both Activity3 and Activity2 to finish. If the user returns to this app, he should resume with Activity1.

I have figured out how to do one or the other, but I can't figure out how to handle both cases, if it's even possible. Can I trap the "Back" button in Activity3 and send a message back to Activity2 telling it not to finish()? It seems like the Activities follow the same lifecycle flow (Pause, Stop) regardless of what you do to send them to the background. Just to answer the question of why I want this behavior, imagine that Activity1 is a login screen, Activity2 is a selection screen, and Activity3 is a content screen. If I press Back from the content page, I want to be able to make a new selection. If I exit via any other means (Home, notification bar), I want the user to be "logged out".

View 2 Replies View Related

Android :: Starting Second Activity From Main Activity On Button Click

Dec 4, 2009

Need an example of how to create/start a new activity from the main activity. I have a button click event on the main layout. Originally I just used setContentView(R.layout.secondactivity); which brings up the layout but I don't think that is correct since the secondactivity class is not instantiated at this point yet. I have looked for such an example and can not find one.

View 3 Replies View Related

Android :: App Widget Configure Activity Opens Main Activity

Jan 10, 2010

I hav an app that is like a relational database. There is a main app activity that users manage things with. There is also a widget that will display important info and add data to the database. When the widget is clicked, a configure class displays a way for the user to edit data. When the configure activity is done, the widget is updated and instead of going back to the home screen, the apps main activity is started. I can't find where the main activity is being called from. Wouldn't I have to create an intent and start Activity() to get this behavior? When done updating, I want the home screen and not my app.

View 3 Replies View Related

Android :: Way To Invoke A Web Service Through A Button

Aug 11, 2010

I'm trying to make an app where a button will invoke a web service's API call (it'll be my own web service; the call/functionality is not relevant). I know how to make a new listener that invokes an activity, but that is insufficient here since I'll still need to make a call out to a web service through it. What is it I'm doing here? Is this a service that I'm looking at? content provider that I'll be invoking that somehow gets data from a web service?

View 2 Replies View Related

Android :: Stopping Widget's Service When Not In Use

Jun 3, 2010

I'm having trouble getting my widget to stop hogging so many resources.I setRepeating on the AlarmManager to update. When the widget is deleted (onDisabled()), I call .cancel() on the service, but the service still shows up in the android "running processes" making me believe I'm doing something wrong.Also, should I be scheduling my updates in the onEnabled() or the onUpdate()? onUpdate doesn't seem to work on anything other than the first widget.

View 1 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

Android :: Binding Service To Activity

Dec 16, 2009

I am working on an android application, where the activity binds to a local service to perform certain tasks.Now I am binding the service in the OnCreate method of the Activity, after which the activity has to use the service object to invoke the functionality defined in the servicein the OnStart method. The problem here is that once a call "bindservice" has been made, we might not get the serviceobject immediately, so my service object would be null till that time. So i cannot invoke the service functions.So is there a way to determine in the activity that the service has been bound and the service object is valid and could be used now. For reference i'm attaching a code snippet for the same.

View 2 Replies View Related

Android :: Activity Service Binding

Mar 13, 2010

Can an Activity be bound to two different Services at the same time or do I have to unbind one Service before binding to the other one?

View 2 Replies View Related

Android :: Stopping Other Activity From My Service..

May 6, 2010

I want to stop an Activity that is in some other application from my Applications service. Is there any mechanism to do so?

View 6 Replies View Related

Android :: Possible To Close Activity From Service

Aug 8, 2010

Is it possible to close/finish activities in activity stack from a backgorund service.

View 2 Replies View Related

Android :: Service Gets Killed - Due To Activity?

Jun 10, 2010

I have a service running in the background. It starts on device boot. Also, I have one activity (that appears in the task launcher) in which I have provided buttons to start and stop the service.

Now, I install the application on the phone and I start the service using this activity (and not on-device boot). As expected the service starts and starts doing its designated task. I no-longer need the activity. So it goes out of sight and may not be required for a long time now.

My question is, now, if the android platform kills this activity, will it kill my service too ? (This is because I see that after few hours, my service is not running anymore.). If this is true, then will the service continue running longer if the service was started on device boot.

View 11 Replies View Related

Android :: Kill A Service By Another Activity?

Feb 16, 2010

Activity 1 starts a Service, using the standard Intent. Activity 1 starts Activity 2. Then, Activity 1 gets finished().

Now, there's only Activity 2.

How does Activity 2 kill the Service, since that Intent was generated in Activity 1? I don't want to pass the Intent everywhere...

View 2 Replies View Related

Android :: Start Activity From Service

Aug 31, 2010

Android:

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

I launched this service from activity

In activity if condition satisfies start

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

From my location service mentioned above could not launch activity, how can i get context of current running activity in service class.

View 1 Replies View Related

Android :: Activity Bound To A Service

Apr 12, 2010

Is there a way to find out if an activity is bound to a service? Something like boolean isBoundToService(ServiceConnection sc)?

Sometimes when I play around with my app I get an exception when it tries to unbind a service which is not bound.

View 1 Replies View Related







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