start a remote service and receive a result in Android

后端 未结 2 602
余生分开走
余生分开走 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:

    
    

    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.

提交回复
热议问题