Android :: Android Service Design - Start With Activity Or When Needed?

Nov 24, 2010

I'm an android noob that is looking for some advice on how to properly use a service in Android. I am building an app that will connect to a server on the Internet to get a data stream via TCP. That data then needs to get send out to another device that is connected via a bluetooth serial port. I want this to continue to function in the background while the user looks at a different activity. The app will be a NTRIP client, which pulls real time RTK correction data from the Internet and sends it to a RTK GPS receiver that I connect to via bluetooth. The data rate will be about 500 bytes/second. The user interface is a single button to connect or disconnect the data stream and some text to show status of the GPS receiver. There are also a few settings that will need to be configured by the user such as the IP/port of the server to connect to and the bluetooth device to communicate with.I think I need to have the main activity spawn a local service, and then have the service spawn a thread for the TCP stream and another thread for the bluetooth connection. Does this sound right? What is the best model for the service in this scenario?-Start(bind) the service every time the activity starts, and have the connect/disconnect button send commands to the service to start/stop the threads. If I go this route, the service will continue to run after the user disconnects and goes to another app. The service would need an inactivity timer to terminate itself.-Start and stop the service when the user presses the connect/disconnect button. The service only runs when data is moving. If I do this, the activity will need to see if the service is running when the activity starts, in order to know if it should bind to the service or tell the user that the link is disconnected.

Android :: Android Service design - start with activity or when needed?


Android :: How To Design Activity And Service Writing To Same Table?

Jun 14, 2010

I have an activity which starts a (intent)service. Both access the same DB and potentially write to the same table. What design pattern would you recommand to avoid concurrency?

View 2 Replies View Related

Android :: Activity Bind To Service - Multiple Thread Design

May 28, 2010

A new question about android and services. Currently I'm developing a App that should send images to a server. It should also be possible to send more images parallel. I made a service that creates for every image a new image. The activity can bind to that service and gather information about the progress. I want to show the current status for every image in a notification (and when the user clicks a notification, an activity with the progress for that image should be shown). But I get several problems with that approach. There are errors with binding, the notification pending event starts the activity completely new, so I lose information about currently sending images and so on. How I could design in a appropriate way.

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 :: 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 :: 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 : GL SurfaceView Renderer Design Needed

Dec 21, 2009

I've been trying to figure out how to get to the current EGLContext from the GLSurfaceView. I looked at the APIs and looked at the code but it doesn't seem like there is any path to it. I could have just missed it - please correct me if I have, but it wasn't obvious. Now, I can totally understand the designer thinking that we should protect people from the context because they can cause bad things to happen but actually it would be nice to have access to swapbuffers so that we can do some effects. Fair enough, though.

The one thing I wanted was to see the current EGLConfig so that I could find out what config attributes I'm getting on weirdly-behaving devices like the Galaxy. It seemed easy enough - it's passed in to Renderer in the onSurfaceCreated method:

public void onSurfaceCreated(GL10 gl, EGLConfig config);

Great! Except wait, you can't query an EGLConfig without an EGLDisplay and that's locked up in the GLSurfaceView. So why is it passed in to the surface created method? Isn't it useless? Accord to GLES spec, an instance of EGLConfig is only good if you have the display/context instances that it was created from.

I didn't try querying it with the default context because it's supposedly invalid but perhaps someone could shed some light on this? I'd love if it were something dumb and obvious that I don't know about.

View 4 Replies View Related

Android :: Start Activity From Service - And Getting Result From It

Feb 11, 2010

I have a Service which needs to receive data from external packages. So, to locate the data providing external packages, I use activity- filter and PackageManager.queryIntentActivities function to locate the interesting packages. Now, from each such package, I need to get a ContentProvider URI. So I want to start the external Activity and the external activity will return a result to my service - something like "startActivityForResult". The problem is that there is no way to call "startActivityForResult" from a Service, only Activity can do that, and my project does not have any Activity, and probably can't show UI for the user.

The bottom line: Can anyone suggest a way to get ContentProvider URI from an external package, while my package has only a Service?

View 22 Replies View Related

Android :: How To Start Activity From Service - If Not Already Started

Mar 19, 2010

I've successfully implemented a BootReceiver, AlarmManager, and Service per the code here: http://github.com/commonsguy/cw-advandroid/tree/master/SystemServices...

Inside the doWakefulWork method of the Service I am instantiating a few classes, but some of them require my Activity to be running. How do I actually start the Activity? The code above only starts the AlarmManager and Service.

There are also times where the Activity *is* already started, like if the user manually opened it. So I also need to start the Activity "only if it's not already running". Hows that work?

And what about the situation where the user first installs your application and may not even reboot their phone for a week. In that case, do you have to start the Service from the Activity? But then the Service will die with the Activity.

View 7 Replies View Related

Android :: How To Wait For Service On Activity Start

Nov 2, 2010

I am making an application that has Activity which communicates with a single service, and is used to start, stop or change settings of that service. I used a singleton approach from this tip.

My problem is that busy-waiting is not working for me and I can't attach a listener to the service because activity gets blocked. I want the service to start or get it's current instance at application start so I put the busy-waiting in onCreate. I'm guessing I'm doing this very wrong, so how do I do this appropriately?

View 2 Replies View Related

Android :: Analog Of Start Activity For Result For Service

Jul 14, 2010

Despite similar question was asked, I have differnet situation: My app consists mostly of a background Service. I want to start external activities and get results back.I see several options:Create dummy Activity and keep reference to it for using its startActivityForResult. This consumes quite a lot of memory, as we know. Use Broadcast Intents instead of Android's results infrastructure: ask client activities to broadcast their results before closing. This kind of breaks the idea and not so performance-efficient. Use Instrumentation directly - try to copy code from startActivityForResult into my Service. Use Service interfaces - serialize and add AIDL connection to the Intent for starting an Activity. In this case Activity should call Service directly instead of providing result. The third approach feels closer to Android for me, but I'm not sure if it's possible to do - Service does not have its Instrumentation, and default implementation seems to always return null.

View 1 Replies View Related

Android :: Start Activity From Service - Running In Background

Nov 13, 2009

I want to develop a application that continuously running in background as service. And after that if i press any numeric key, it should start an application.

I have developed a service which is running continuously. Is it possible in Android?

View 2 Replies View Related

Android :: Activity Is Unable To Start Service In Same Package / What I Am Missing?

Jun 9, 2009

I have a service class my.app.MyService that I'm attempting to launch from my.app.MyActivity as follows:

Intent svc = new Intent( this, MyService.class );

The manifest contains the entries:

<uses-permission android:name="android.permission.ACCESS_BACKGROUND_SERVICE" />

<service android:name =".MyService" />

LogCat gives the message:

"Unable to start service Intent { comp={"my.app/ my.app.MyService" } } : not found"

Could someone kindly let me know what I am missing?

View 3 Replies View Related

Android :: Unable To Start Service Intent Service Not Found

Aug 20, 2009

I am getting following message when i try to launch service.Also is there any specific path on file system where we need to place the .apk file which contains my serivce component only.

View 2 Replies View Related

Android :: Design Considerations - Sync Process And Using Service

Sep 29, 2010

I'm designing an android app which will need to do the following steps:

1. User pushes a button or otherwise indicates to "sync data".
2. Sync process will use rest web services to move data to and from the server.
3. The data will be stored locally in a sqlite database.
4. The sync process should provide status updates/messages to the UI
5. The user should not be allowed to wander off to other parts of the application and do more work during the sync process.

The first time the sync process runs, it may take 10-20 minutes. After the initial sync, less data will be transferred and stored and I expect the process to take 1-2 minutes or less. I've been doing a lot of reading about android's AsychTask and various examples of using a Service. But I don't fully understand the design considerations and trade-offs of choosing one design over the other. I currently have my demo project stubbed out using an AsychTask. After watching (most of) Developing Android REST client applications:
http://code.google.com/events/io/2010/sessions/developing-RESTful-and...
I'm left confused the design patterns described here feel overly complex, perhaps because I just "don't get it" yet.

View 19 Replies View Related

Android :: Design Approach - Web Service And Broadcast Receivers

Sep 23, 2010

I am developing an app for android mobiles that communicates with a json/rest web service. I need to make certain kinds of calls periodically to the server to check for some information. Within that context I might need also to query the GPS for the current position. I'm quite undecided to use a Local Service, since I don't know very well how to deal with them, in fact I need to retrieve those data periodically and refresh a MapView accordingly. I heard that I can use PendingIntents,in the service, associate this data as a payload and send them to a broadcast receiver which unpack the data and refresh the UI, I heard also that this is a bad design approach because of what broadcast receiver are intended to be used for.

View 1 Replies View Related

Android :: What Permissions Are Needed For Writing To A File Using Activity

Aug 27, 2009

Are any <uses-permission> clauses needed in the manifest for: 1. Writing to a file using the Activity.openFileOutput() mechanism; 2. Writing to the SD card using FileOutputStreams; 3. Sending email using the Activity.startActivity( Intent.create Chooser (...)) mechanism
http://developer.android.com/guide/topics/security/security.html and didn't see anything that seemed relevant. My app works on my ADP1 without any <uses-permission> clauses when installed with "adb install xyz.apk" but I was worried that it may have problems on a "real" consumer device.

View 2 Replies View Related

Android :: Design Clarification In Android List Activity Vs Activity

Mar 25, 2010

I have a simple question. I am trying to design a simple Android app, which based on keywords searches something and shows a listing view of results. Currently it merely searches SMSes in the cellphone.Here are some of the things I am faced with: I have a simple first page with a textbox and a submit button. It's rendered by "Activity" inherited class call SMS Finder.once I have the results present with me, I want them to be binded to a list view. Showing preview text to limited characters, say 20 chars. Clicking on the same should "ideally" open the inbox (or outbox or whatever) and open the SMS, however that meant I cannot come back to my app easily. So I would rather open the whole SMS in my own app. So clicking on the app should open the SMS in a new screen with complete message, sender info etc. Few questions here, For generic Android phone apps, what are the best practices to make UI as compliant to as many phones? Like what kind of views should I use?

View 1 Replies View Related

Android :: Activity Design Advice

Mar 3, 2010

I have a service running that grabs the users attention with a notification. What i would like to happen when the user clicks on the notification is for it to launch a dialog box. The "proper" thing to do is to launch an activity in this way, so is there a way to get an activity to launch with out filling the screen? So it looks like a dialog box?

View 5 Replies View Related

Android : Multiple Handlers Design In An Activity Failed

May 14, 2010

This question is related to an existing question I asked. I though I'll ask a new question instead of replying back to the other question. Cannot "comment" on my previous question because of a word limit. Marc wrote - I've more than one Handlers in an Activity." Why? If you do not want a complicated handleMessage() method, then use post() (on Handler or View) to break the logic up into individual Runnable. Multiple Handlers makes me nervous. I'm new to Android. Is having multiple handlers in a single activity a bad design ?

I'm new to Android.My question is - is having multiple handlers in a single activity a bad design ? Here is the sketch of my current implementation. I've a mapActivity that creates a data thread (a UDP socket that listens for data).

My first handler is responsible for sending data from the data thread to the activity. On the map I've a bunch of "dynamic" markers that are refreshed frequently. Some of these markers are video markers i.e., if the user clicks a video marker, I add a ViewView that extends a android.opengl.GLSurfaceView to my map activity and display video on this new vide.

I use my second handler to send information about the marker that the user tapped on ItemizedOverlay onTap(int index) method.The user can close the video view by tapping on the video view. I use my third handler for this. I would appreciate if people can tell me what's wrong with this approach and suggest better ways to implement this.

View 2 Replies View Related

Android : Design - Launch An Activity Based On Type Of A View

Nov 4, 2010

Should I create a Listener within a BaseAdapter or should I pass it in? I have 4 classes that inherit from a base class. I pass the Adapter a list objects.

The Adapter is eventually used with a ListActivity I want to create a View based on the derived class and I want them to launch an Activity based on the type of a View. Currently I create the intent and Listener in the BaseAdapter. Is what I'm doing a good pratice?

View 1 Replies View Related

Android :: Start An Activity And Return Back To Original Activity

Jan 26, 2009

I have an application with contains multiple activities. The main activity will start the others ( use startActivity() ) depends on user event, when an activity close, it calls finish() and return back to main activity. It appears to behavior like that.

However, the "problem" I see is main activity's onCreate function is called every time. I think the the main activity should be placed in the activity stack and simply push to front when others exit, therefore only onResume, onStart are called. Is there some flag I need to set or I misunderstand the activity behaviro?

In child activity, besides calling finish() or startActivity for main activity, what is other way to move main activity to front?

View 2 Replies View Related

Android :: Start Activity When Main Activity Is Running In Background

Jan 10, 2010

I created an application which enables the user to set whether he wants to receive notification while the application runs in background mode. If the notifications are enabled an activity should be started (the dialog should appear on the screen).

I tried to enabled it the following way:

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

This is the method from main activity. When onPause() is executed isRunningInBackground is set true.
When I tried to debug it when the main application was running in the background the line

startActivity(intent) had no effect (the activity didn't appear).

Does anyone know how to midify the logic in order to start an activity from the main activity when the main activity is running in the background (after onPause() is called)?

View 1 Replies View Related

Android :: Start An Activity In Different Apk Using StartActivity - Using The Activity Name Or Similar

Apr 20, 2010

I have tried to write an Android application with an activity that should be launched from a different application. It is not a content provider, just an app with a gui that should not be listed among the installed applications. I have tried the code examples here and it seems to be quite easy to launch existing providers and so on, but I fail to figure out how to just write a "hidden" app and launch it from a different one.

The basic use case is:

App A is a normal apk launchable from the application list.

App B is a different apk with known package and activity names, but is is not visible or launchable from the application list.

App A launches app B using the package and class names (or perhaps a URI constructed from these?).

I fail in the third step. Is it possible to do this?

View 3 Replies View Related

Android :: Start Activity And Clear Activity History

Apr 22, 2010

I have a huge maze of activities in my application. What I need to do, is that when the user logs in into the system, the activity history should be cleared. I cant just use finish() when I start a new activity, because I want the activities to have a history until the user logs in. I have experimentet with the different flags when starting an activity, but I have had no success.

View 1 Replies View Related







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