破坏后恢复的活动?(活动生命周期)需要帮助 [英] Restore activity after destruction ?(Activity Lifecycle) Help needed

查看:234
本文介绍了破坏后恢复的活动?(活动生命周期)需要帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

家伙,您好我有一个应用程序,它几乎完全complete.It是一个音乐player.It从服务播放音乐。

Hi guys i have an app which is almost totally complete.It is a music player.It plays music from a service.

当我preSS回按钮启动该服务活动明显破坏。(我想的活性被破坏,使用户可以浏览其他活动。本原因,我告诉这是因为单| singleinstance等将不解决我的问题),但我不知道我怎么可以重新从通知的活动。
此外,当它启动该服务的活动是可见的(而不是破坏),那么太多,如果我的通知点击,我的应用程序停止unexpectedly.And因此,我有两个问题要解决这里。

When i press back button that activity which started the service is obviously destroyed.(i want the activity to be destroyed so that the user can navigate other activities.The reason i am telling this is because singleton|singleinstance etc won't solve my problem) But i don't know how i can recreate the activity from the notification. Also when the activity which started the service is visible(and not destroyed) then too if i click on the notification, my app stops unexpectedly.And hence i have two problems to solve here.

我使用的是全局变量这是一个列表,所以我不认为我需要保存数据之前destruction.I想我知道这个概念的活动状态如何得到恢复和重建,但我觉得我没有完全知道怎么会这样done.I我不知道在该方法中的活动状态应恢复以及如何可以恢复?另外,我开始在的onCreate method.Should我将其更改为其他方法的服务?能否启动恢复活动时的onCreate服务有问题?

I am using a global variable which is a list and hence i don't think i need to save data before destruction.I think i know the concept how the activity state can be restored and recreated but i think i am not totally aware how it can be done.I am not sure in which method the activity state should be restored and how can it be restored ??Also i am starting the service in onCreate method.Should i change it to some other method?Can starting the service in onCreate be a problem when restoring the activity ?

额外注意:全局变量是整个应用程序提供独立的个体行为,因为他们扩展的应用。还捆绑只会帮助活动时被销毁由system.When pressing后退按钮,我们明确地破坏活动,因此数据不能保存到包的onSaveInstanceState作为永远不会由活动调用。

Extra Note :Global Variables are available throughout the application and are independent of an individual activity,as they extend Application.Also Bundle will only help when the activity is destroyed by the system.When Pressing the back button we explicitly destroy the activity and hence data cannot be saved into the bundle as onSaveInstanceState is never called by the activity.

推荐答案

您可以播放和基于类似活动的生命周期停止播放机
在onPause - 你应该叫player.stop()
 onresume你应该调用播放和
你的OnDestroy需要释放你的播放器实例。

You can play and stop your player based on Activity life cycle like OnPause -you should call player.stop() onresume you should call play and ondestroy you need to release your player instance.

调用线程服务内获得从服务器数据,这样它会顺利工作

call a thread inside your service to get data from server so that it will work smoothly.

您应该调用释放释放MediaPlayer的实例或复位。

you should release mediaplayer instances by calling release or reset .

您可以在通知使用挂起的意图,所以当你看到通知,那么你就可以打开你的任何活动正在申请中提到的意图

You can use Pending intent in notification so when you will see notification then you can open your activity whatever mentioned in pending intent.

这篇关于破坏后恢复的活动?(活动生命周期)需要帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆