Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
这就是我想要在我的应用程序中做的事情。
活动有 2 个按钮
1 - 用于启动线程 (start) 2 - 用于停止线程 (stop)
我按下一个按钮来启动一个线程,我不想在按下一切正常时杀死我的线程。
问题是当我回到那个活动时,有一个按钮可以停止那个线程但是线程丢失了所以我不能停止它,如果我按下启动第二个线程运行并且我有 2 个线程运行。
我的问题是我们可以将该线程保存在一个包中吗?如果可能的话,我怎么看不到放置对象的方法。如果不是我可以做的任何好的解决方案来避免丢失我的线程。
谢谢你。
您无法将线程保存在 Bundle 中。一般来说,如果您需要在退出应用程序后运行任务,您应该使用Service。