Bug 8510 - TaskAsync Launching Multiple Times
Summary: TaskAsync Launching Multiple Times
Status: RESOLVED INVALID
Alias: None
Product: Android
Classification: Xamarin
Component: General ()
Version: 4.2.x
Hardware: PC Mac OS
: High normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-11-19 16:16 UTC by Pierce Boggan [MSFT]
Modified: 2014-01-13 09:50 UTC (History)
4 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
The Test Case for the issue (1.21 MB, application/octet-stream)
2012-11-20 02:27 UTC, Omar
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED INVALID

Description Pierce Boggan [MSFT] 2012-11-19 16:16:21 UTC
Steps to Reproduce:

1- Open the app in a Emulator or Device. In the OnCreate method I launch the Task or Thread. 

2- You can Navigate to other activitys, and go back to the Main Activity and the Task or Thread are not launching again.

3- When you are in the Main activity click the back button of the Emulator or Device:

4- The application goes to background and the Task or Thread continues running which its fine, that's what I want.

5- Now from your Emulator or Device open again the application.

6- Now you can see the Task or Thread launch twice, and if you repeat the steps it will launching more.

How can I detect a running one to not launching again. Because this line don’t work if (_task == null)

When the app goes to background and you open it again _task is always null.
Comment 2 Omar 2012-11-20 02:27:10 UTC
Created attachment 2975 [details]
The Test Case for the issue
Comment 3 Jonathan Pryor 2014-01-13 09:50:09 UTC
> 6- Now you can see the Task or Thread launch twice

What does this mean? Is there more than one Tasky process running (`adb shell ps | grep Tasky`)? Is Activity.OnCreate() re-executed (I'd expect this behavior)?

> How can I detect a running one to not launching again. Because this line don’t
> work if (_task == null)
> 
> When the app goes to background and you open it again _task is always null.

This is expected and By Design:

http://docs.xamarin.com/guides/android/application_fundamentals/activity_lifecycle/

Activity1._task is an instance member. Consequently, its value is tied to the lifetime of the Activity instance.

The Activity instance's lifetime is in turn managed by Android, and when you tap the Back button the Activity instance is _destroyed_:

http://docs.xamarin.com/guides/android/application_fundamentals/activity_lifecycle/#Back_vs._Home

If you need to have state that is tied to the process, it must not be a member of an Activity. It should either be part of an Android.App.Application, or it should be hosted by a Android.App.Service or other type. Activities are constantly created and destroyed for a variety of reasons; app-global state SHOULD NOT be solely referenced by Activities.