服务已实现onTaskRemoved()方法.
当通过swipe从recent-apps-list中删除应用程序时调用startService()onTaskRemoved()时启动服务.
但是如果服务以bindService()开头,则onTaskRemoved()从不调用.
如何在使用bindService()启动应用程序后,通过轻扫将应用程序从recent-apps-list中删除,从而调用onTaskRemoved()?
以下方法调用如果以下:
1. bindService():
Activity? onCreate()
CustomService? onCreate()
CustomService? onStart()
CustomService? onStartCommand()
CustomService? onBind()
// Here we swipe to remove app from recent-apps-list
CustomService? onTrimMemory()
2. startService():
ActivityA? onCreate()
CustomService? onCreate()
CustomService? onStart()
CustomService? onStartCommand()
CustomService? onBind()
// Swipe to remove app from recent-apps-list
CustomService? onTrimMemory()
CustomService? onTaskRemoved() // <=====
CustomService? onUnbind()
Run Code Online (Sandbox Code Playgroud) 我有一个TabBarActivity
托管片段的活动EquipmentRecyclerViewFragment
.该片段接收LiveData回调,但Activity不接收(在调试模式下使用断点进行校对).奇怪的是,如果我调用ViewModel的initData
方法,Activity回调会触发.以下是上述组件的相关部分:
TabBarActivity
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
initVM()
setContentView(R.layout.activity_nav)
val equipmentRecyclerViewFragment = EquipmentRecyclerViewFragment()
supportFragmentManager
.beginTransaction()
.replace(R.id.frameLayout, equipmentRecyclerViewFragment, equipmentRecyclerViewFragment.TAG)
.commit()
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener)
}
var eVM : EquipmentViewModel? = null
private fun initVM() {
eVM = ViewModelProviders.of(this).get(EquipmentViewModel::class.java)
eVM?.let { lifecycle.addObserver(it) } //Add ViewModel as an observer of this fragment's lifecycle
eVM?.equipment?.observe(this, loadingObserver)// eVM?.initData() //TODO: Not calling this causes Activity to never receive the observed ?
}
val loadingObserver = Observer<List<Gun>> { equipment ->
...}
Run Code Online (Sandbox Code Playgroud)
EquipmentRecyclerViewFragment
override …
Run Code Online (Sandbox Code Playgroud) 我需要Azure中的registrationId.是否可以从Azure获取registrationId?
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *) deviceToken {
SBNotificationHub* hub = [[SBNotificationHub alloc] initWithConnectionString:HUBLISTENACCESS
notificationHubPath:HUBNAME];
[hub registerNativeWithDeviceToken:deviceToken tags:nil completion:^(NSError* error) {
if (error != nil) {
NSLog(@"Error registering for notifications: %@", error);
}
else {
[self MessageBox:@"Registration Status" message:@"Registered"];
}
}];
}
Run Code Online (Sandbox Code Playgroud)
通知工作正常,但我需要Azure中的registrationId发送回服务器.
我在此处、此处、此处和此处查看了与此问题相关的 SO 帖子,但我对提出的修复程序没有任何运气。每当我运行命令时,docker-compose -f stack.yml up
我都会收到以下堆栈跟踪:
Attaching to weg-api_db_1, weg-api_weg-api_1
db_1 | 2018-07-04 14:57:15.384 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
db_1 | 2018-07-04 14:57:15.384 UTC [1] LOG: listening on IPv6 address "::", port 5432
db_1 | 2018-07-04 14:57:15.388 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1 | 2018-07-04 14:57:15.402 UTC [23] LOG: database system was interrupted; last known up at 2018-07-04 14:45:24 UTC
db_1 | …
Run Code Online (Sandbox Code Playgroud)