start a remote service and receive a result in Android

后端 未结 2 587
余生分开走
余生分开走 2020-12-20 08:52

I have two applications. One app has the Activity and another one is a background service.

I can able to access the service app from my activity app using implicit i

相关标签:
2条回答
  • 2020-12-20 09:18

    First add a class like this:

    package com.test.context; //For example
    public class MyContext extends Application
    {
       //Here you define the attributes to share through the application
       // with setters and getters
    }
    

    and in the AndroidManifest.xml, add the path of the class, in the example is com.test.context so:

    <application android:name="com.test.context.MyContext"
                     android:icon="@drawable/ic_launcher"
                     android:label="@string/app_name">
    

    Then in your code you can do some like this:

    MyContext ctx = (MyContext)getApplication();
    

    And you will be able to share data in all the app, btw activities and services, i did it this way in a Tasker , and works fine.

    0 讨论(0)
  • 2020-12-20 09:31

    Why do you want to communicate through intent while there is a perfectly working binder protocol.

    http://developer.android.com/guide/topics/fundamentals/bound-services.html

    If an activity starts a service with 'bindService()' then the service will run until the activity calls 'unbindService()'.

    0 讨论(0)
提交回复
热议问题