Android app in the background

Asked

Viewed 1,244 times

5

I’m working on the open source project Linphone,when the application is closed is not working in the background, so if someone makes a call to me in the meantime I am not notified, how can I treat this problem?

  • You must create a service, for your app, here has a tutorial explaining how to make an implementation.

  • Thanks @Marcogiovanni, I’ll take a look at this tutorial.

1 answer

1


A Service is a component of what can perform long operations and does not provide a user interface. Another application component can start a service and it will continue running on background even if the user switches to another application.

[...]In addition, a component may link to a service for interact with it and even establish inter-process communication (IPC). For example, a service can handle network operations, play music, run I/O files, or interact with a provider of content, all from the background.

Here you go an example in which you can use.

Service in manifest.xml

<manifest ... >
  ...
  <application ... >
      <service android:name=".ExampleService" />
      ...
  </application>
</manifest>

The class IntentService provides a simple structure for the execution of a transaction in a single background segment. This allows you to handle long-term operations without affecting the responsiveness of your user interface.

This is a subclass of Service that uses a work chaining to handle all startup requests, one at a time. This is the best option if you don’t want the service to handle several requests simultaneously. All you need to do is implement onHandleIntent(), which receives the intention for each request from start so you can carry out the background work.

To create a component IntentService for your app, set a class that extends Intentservice, and within it, define a method that replaces onHandleIntent(). For example:

public class RSSPullService extends IntentService {
    @Override
    protected void onHandleIntent(Intent workIntent) {
        // Gets data from the incoming Intent
        String dataString = workIntent.getDataString();

    }
}

For more details, check the documentation.

  • The Intentservice will not be the most suitable component for what the AP wants. It is useful to perform a task and finish, for example a download or upload. In the case of the question would be to use a Service that will always be running waiting for "a call".

Browser other questions tagged

You are not signed in. Login or sign up in order to post.