excuse my English, I need to know how to make a POST to an external data base when the app is closed, I really do not know how or tools used or even if possible, I thank in advance the advice and answers.
请原谅我的英语,我需要知道如何在应用程序关闭时对外部数据库进行POST,我真的不知道如何使用或使用工具,甚至可能,我提前感谢建议和答案。
3 个解决方案
#1
0
As people have already commented, you will want to make the request using an HTTP library such as OkHttp in a background Service
. The Service
lifecycle is independent of the Activity
s, but is still part of the Application
, therefore care needs to be taken to make sure the Service
is defined correctly for your needs (For example, whether you need to Service
to be restarted if it's killed by the system START_STICKY
). See the links below for more details:
正如人们已经评论过的那样,您将希望在后台服务中使用诸如OkHttp之类的HTTP库来发出请求。服务生命周期独立于活动,但仍然是应用程序的一部分,因此需要注意确保根据您的需要正确定义服务(例如,如果服务被重新启动,是否需要重新启动服务系统START_STICKY)。有关详细信息,请参阅以下链接:
http://developer.android.com/training/run-background-service/index.html http://developer.android.com/guide/components/services.html
http://developer.android.com/training/run-background-service/index.html http://developer.android.com/guide/components/services.html
#2
0
I do not know about the exact event on exit callback function in the android activity. but you can definitely call restful service from android application.
我不知道android活动中退出回调函数的确切事件。但你绝对可以从Android应用程序调用restful服务。
I have used spring for android to call restful services. check out the below link Spring for android
我用spring for android来调用restful服务。看看以下链接Spring for android
#3
0
Yes you can do, You can use BroadcastReceiver
to start a service in background. BroadcastReceiver can be triggered by some events. You can read about it more on BroadcastReceiver.
是的,你可以这样做,你可以使用BroadcastReceiver在后台启动服务。 BroadcastReceiver可以由某些事件触发。您可以在BroadcastReceiver上阅读更多内容。
#1
0
As people have already commented, you will want to make the request using an HTTP library such as OkHttp in a background Service
. The Service
lifecycle is independent of the Activity
s, but is still part of the Application
, therefore care needs to be taken to make sure the Service
is defined correctly for your needs (For example, whether you need to Service
to be restarted if it's killed by the system START_STICKY
). See the links below for more details:
正如人们已经评论过的那样,您将希望在后台服务中使用诸如OkHttp之类的HTTP库来发出请求。服务生命周期独立于活动,但仍然是应用程序的一部分,因此需要注意确保根据您的需要正确定义服务(例如,如果服务被重新启动,是否需要重新启动服务系统START_STICKY)。有关详细信息,请参阅以下链接:
http://developer.android.com/training/run-background-service/index.html http://developer.android.com/guide/components/services.html
http://developer.android.com/training/run-background-service/index.html http://developer.android.com/guide/components/services.html
#2
0
I do not know about the exact event on exit callback function in the android activity. but you can definitely call restful service from android application.
我不知道android活动中退出回调函数的确切事件。但你绝对可以从Android应用程序调用restful服务。
I have used spring for android to call restful services. check out the below link Spring for android
我用spring for android来调用restful服务。看看以下链接Spring for android
#3
0
Yes you can do, You can use BroadcastReceiver
to start a service in background. BroadcastReceiver can be triggered by some events. You can read about it more on BroadcastReceiver.
是的,你可以这样做,你可以使用BroadcastReceiver在后台启动服务。 BroadcastReceiver可以由某些事件触发。您可以在BroadcastReceiver上阅读更多内容。