小编Jam*_*lor的帖子

服务:如果使用bindService启动,则不会调用onTaskRemoved

服务已实现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)

android android-service android-service-binding

17
推荐指数
1
解决办法
1万
查看次数

LiveData观察者未被调用

我有一个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)

android mvvm android-fragments kotlin android-livedata

8
推荐指数
1
解决办法
7586
查看次数

如何从iOS中的Azure notificationhub获取registrationId

我需要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发送回服务器.

azure apple-push-notifications ios azure-notificationhub

5
推荐指数
1
解决办法
346
查看次数

运行 docker compose 会导致“连接到 localhost:5432 被拒绝”。例外

我在此处此处此处此处查看了与此问题相关的 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)

postgresql docker spring-boot docker-compose

3
推荐指数
1
解决办法
3964
查看次数