简体   繁体   English

C#Android在活动更改时使线程保持活动状态

[英]C# Android Keep thread alive on Activity Change

I am new to Android Visual Studio. 我是Android Visual Studio的新手。 I have an app which has two Activities. 我有一个包含两个活动的应用程序。 It is possible as user to switch between the two Activities. 用户可以在两个活动之间切换。 The second Activity has a Thread running in the event OnCreate. 第二个活动有一个在事件OnCreate中运行的线程。 The method which runs in a separate Task Thread is updating data and can take a bit more time. 在单独的任务线程中运行的方法正在更新数据,可能会花费更多时间。 If the Update is running the user has still the possibilty to switch back to the first Activity. 如果更新正在运行,则用户仍然可以切换回第一个活动。 In this case I have a destroyed Update. 在这种情况下,我的销毁更新了。 Is there any way I can go to have that update running completly through. 我有什么办法可以使更新完全运行。 I need a solution how to let the thread finish its update without being stopped due to the Destroy\\Close event ? 我需要一个解决方案,如何使线程完成更新而不会由于Destroy \\ Close事件而停止? Any help or idea is appreciated. 任何帮助或想法表示赞赏。 Thanks 谢谢

SOLUTION: 解:

just implement an application class in your MainActivity.cs and run the thread from the app class 只需在MainActivity.cs中实现一个应用程序类,然后运行该应用程序类中的线程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM