Android 文档谈到 onStop 和 onDestroy 在某些情况下无法调用,但我没有发现任何与片段相同的内容。是否始终调用 onPause、onStop、onDestroyView、on Destroy 和 onDetach?仅在暂停时?
我知道以下问题与代码没有直接关系,但我们确实需要一些有关推送通知最佳实践的输入。
我们目前正在构建一个聊天应用程序,该应用程序使用推送通知来通知用户有新消息可用。这不是什么新鲜事,也不是什么奇特的东西……我们也已经有了允许我们做到这一点的代码:
然而,我的问题是当应用程序用户上下文发生变化时该怎么办。例如:
目前我们遇到的问题是,应用程序仍然收到来自用户 A 的推送通知,因为推送服务器认为该设备仍在用户上下文 A 下。
当然,我们可以实现一个注销功能,在注销时删除设备,但如果应用程序被删除并重新添加,会发生什么情况。例如:
此时,即使没有用户登录,设备也会再次收到来自用户 A 的推送通知。
在我看来,我们在思考中错过了关键的一步,但我们不知道那是什么……我们不能请求新的设备令牌。
提前致谢
网络电话:-
static func getProfile(parameters:[String:AnyObject], onComplete:[String:AnyObject]->()) {
var requiredData:[String:AnyObject] = [:]
Alamofire.request(.GET,API.getProfile,parameters: parameters).validate().responseJSON { (response) in
if let responseData = response.result.value {
if let jsonData = responseData as? [String:AnyObject] {
requiredData["UserName"] = jsonData["UName"]
requiredData["UserEmail"] = jsonData["UEmail"]
requiredData["UserMobileNo"] = jsonData["UPhone"]
requiredData["UserAddress"] = jsonData["UAddress"]
requiredData["UserCity"] = jsonData["UCity"]
}// Inner If
} // Main if
onComplete(requiredData)
}// Alamofire Closed
}// Func closed
Run Code Online (Sandbox Code Playgroud)
所需 VC 内的网络呼叫:-
override func viewDidLoad() {
super.viewDidLoad()
let parameters:[String:AnyObject] = [
"WebKey": API.WebKey.value.rawValue,
"UId":NSUserDefaults.standardUserDefaults().integerForKey("UserId")
]
NetworkInterface.getProfile(parameters) { (responseDictionary) in
//print("Passed Data …Run Code Online (Sandbox Code Playgroud) 我正在制作一个应用程序,其中的一项功能是每 10 秒更新一次用户位置。到目前为止,应用程序没有更新它的位置,因为在检索位置之前,活动已暂停并重新启动。我不明白为什么要重新启动活动。我最好的猜测是,由于没有很多事情发生,操作系统正在暂停活动,但是什么会触发活动重新启动?我之前尝试过构建应用程序,然后我从头开始,因为我犯了太多错误,但即使如此,我以前也没有遇到过这个问题。
D/selectRouteAndTransportMethod: On Start
D/myLocation: Connection Requested
D/selectRouteAndTransportMethod: Connecting
D/selectRouteAndTransportMethod: registered
D/myLocation: Connection Requested
V/FA: Activity resumed, time: 8562145
V/FA: Screen exposed for less than 1000 ms. Event not sent. time: 32
V/FA: Activity paused, time: 8562177
V/FA: onActivityCreated
D/Activity: performCreate Call secproduct feature valuefalse
D/Activity: performCreate Call debug elastic valuetrue
D/selectRouteAndTransportMethod: On Start
D/myLocation: Connection Requested
D/selectRouteAndTransportMethod: Connecting
D/selectRouteAndTransportMethod: registered
D/myLocation: Connection Requested
V/FA: Activity resumed, time: 8562374
D/myLocation: OnConnected
D/myLocation: Permission Was Granted
V/FA: Screen exposed …Run Code Online (Sandbox Code Playgroud) 我想知道应用程序更新时应用程序处于什么状态。
例如:假设我们正在运行一个应用程序(称为 Le Music),它在后台模式下播放音乐。
现在我们去商店看到有可用的更新,然后点击更新。当前版本的乐音乐从旧版本过渡到新版本的生命周期是怎样的?
我需要创建一个登录表单。用户成功登录后,我需要启动某种计时器(例如:3 分钟),因此如果用户对应用程序没有反应,或者如果 Flutter 应用程序状态暂停、暂停或不活动超过 3 分钟,则用户没有反应。该应用程序将转到主登录页面。只要用户与应用程序交互,我就需要取消计时器,并且只需要启动计时器应用程序状态是暂停、暂停或不活动。我怎么做?
我尝试实现“WidgetsBindingObserver”,但它看起来不像我想要的那样工作。如果用户成功输入并在应用程序中导航,则 WidgetsBindingObserver 将失败(错误:小部件的状态对象不再出现在小部件树中)。
我的问题是如何实现基于定时的 Flutter 应用程序生命周期,只要用户与应用程序有交互?如果没有用户交互,生命周期计时器将启动,如果在计时器结束之前有用户交互,则必须取消计时器。
class _MyUserHomePageState extends State<MyUserHomePage> with WidgetsBindingObserver {
AppLifecycleState _appLifecycleState;
@override
void initState() {
_appStatePasue = false;
WidgetsBinding.instance.addObserver(this);
super.initState();
}
// TODO: DID_CHANGE_APP_LIFE_CYCLE
void didChangeAppLifecycleState(AppLifecycleState state) {
setState(() {
_appLifecycleState = state;
if(_appLifecycleState == AppLifecycleState.paused ||
_appLifecycleState == AppLifecycleState.inactive ||
_appLifecycleState == AppLifecycleState.suspending) {
_appStatePasue = true;
print("timer---fired: $_appLifecycleState");
_timer = Timer.periodic(Duration(minutes: 1), _capitalCallback);
print(_appLifecycleState);
} else {
_appStatePasue = false;
}
});
}
// TODO: APP_LIFE_CYCLE__CALLBACK
void _capitalCallback(_timer) …Run Code Online (Sandbox Code Playgroud) 我的包中有一个功能应该谨慎使用。
用户应该意识到这一点,但如果他/她认为情况正常,那么每次调用该函数时都会显示警告。
我经常看到只显示一次的警告。调试它们非常痛苦,所以我找不到可重现的示例(如果有的话,我会添加一个)但它们显示特定的警告消息,然后是rlang信息:
此警告每个会话显示一次
有很多帮助想要调试这些消息(例如这里,这里,或者这里,只是谷歌“r 这个警告每个会话显示一次”)
我认为该软件包lifecyle经常使用那些进行软弃用,但我无法在lifecycle:::lifecycle_build_message.
我怎样才能在我的包裹中抛出这样的警告?
编辑:
这是一个可重现的示例。您必须重新启动 R 会话才能再次显示。如您所见,options(warn=2)没有影响。
options(warn=2)
xx=c("Sepal.Width")
tidyselect::vars_select(names(iris), xx)
Run Code Online (Sandbox Code Playgroud) 我试图检测应用程序关闭时颤动。飞镖有什么办法吗?
我尝试使用WidgetsBindingObserver但 flutter 只能检测 AppLifecycleState 的paused、inactive(我相信在 IOS 上)、resumed和detached。
class ChatScreenState extends State<ChatScreen> with WidgetsBindingObserver{
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
super.didChangeAppLifecycleState(state);
setState(() {
_notification = state;
});
switch (state) {
case AppLifecycleState.paused:
print('paused');
break;
case AppLifecycleState.inactive:
print('inactive');
break;
case AppLifecycleState.resumed:
print('resumed');
break;
case AppLifecycleState.detached:
print('detached');
break;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试关闭我的应用程序,它的打印仅暂停。
我想要做的是当应用程序在聊天屏幕上关闭时。我想在我的firestore上写点东西。但我找不到办法做到这一点。
编辑:我所说的关闭是指我自己故意关闭应用程序。(按主页键并向上滑动)
这是应用程序关闭时的终端日志
D/EGL_emulation( 9248): eglMakeCurrent: 0xdb81aba0: ver 3 0 (tinfo 0xdb80fa70)
I/flutter ( 9248): state = …Run Code Online (Sandbox Code Playgroud) 我正在制作一个包装组件,所以我需要在mounted() 方法中添加所有事件。然而事情是,因为它是另一个组件,每当我打开该组件时,都会触发事件。我不知道如何阻止它。即使我让它在单击组件时被触发,但它没有用。它仅适用于第一次安装。重新打开它(从第二个安装)后,它只会触发所有事件,我必须阻止它。
有没有一种方法可以阻止我不触发 vuejs 的mounted() 钩子中的事件?
编辑:我正在制作传单画包装。所有事件都来自传单绘制文档。
this.addnew() 是被触发的。
objectLayer.on("layeradd", (e) => {
let layer = e.layer;
layer.on("click", onClickFeatureSelct, layer);
if (typeof layer.options.id === "undefined") {
layer.options.id = L.Util.stamp(layer);
}
if (!layer.feature) {
let json = layer.toGeoJSON();
layer.feature = L.GeoJSON.asFeature(json);
}
let properties = layer.feature.properties;
let keyvalue = L.stamp(layer);
if (layer instanceof L.NodeCircle) {
let latlng = layer.getLatLng();
itemType = "node";
let nodes = this.$store.getters.nodeList;
let result = false;
for (let i = 0; i < nodes.length; i++) {
if …Run Code Online (Sandbox Code Playgroud) 我有一个在 Flutter 中开发的应用程序,从后台激活时,我在 IOS 上遇到了一些问题。
在 IOS 上启用了使用位置后台模式。它在后台工作没有任何问题,即使是几天,它也能完成它必须做的事情。但是当我在后台工作较长时间(大约一天或更长时间)后打开应用程序时,UI 被冻结!请注意,如果我在几个小时后这样做,没关系,问题会在更长的时间后出现。
Flutter 版本:[?] Flutter(通道稳定,1.20.1,在 Mac OS X 10.15.5 19F101,语言环境 hu-HU)
我能做些什么来修复它?我应该在 Flutter 中以某种方式重新初始化 UI 吗?或者从本地做任何事情?
非常感谢,任何帮助都非常受欢迎!
lifecycle ×10
ios ×4
flutter ×3
android ×2
background ×1
devicetoken ×1
fragment ×1
java ×1
javascript ×1
ondestroy ×1
r ×1
rlang ×1
swift ×1
timer ×1
vue.js ×1