xamarin/Xamarin.Forms

MainActivity is getting created twice causing app crashing in navigation

Open

#5,813 opened on Apr 4, 2019

 (5 comments) (0 reactions) (0 assignees)C# (1,926 forks)batch import
e/6 :clock6:help wantedi/highinactivep/Androidt/bug :bug:up-for-grabs

Repository metrics

Stars
 (5,644 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

Description

Hitting the home button and then clicking on the app icon in the home screen causes another MainActivity to create again and has weird side effect that causes a crash in the Navigation stack.

NOTE: I am only able to confirm when the apk is build from the IDE and immediately deploy to device for the first time. After the crash, relaunching the app doesn't happen again, but will appear again if you compile and deploy again.

Steps to Reproduce

Sample project https://1drv.ms/u/s!ApQ7q0pIhq0egVXFMuvC5OX1iZIS

  1. Compile and deploy the onto Android device
  2. After the app is launched hit the home button and open the app by finding the app icon in the home screen (if you reopen the app from task manager it does not happen)
  3. If you put a break point in the MainActivity onCreate, you will see that it creates another activity onto the stack 4 a. At this step if you attempt to display an dialogue/alert, the app will crash with "can't attach to view" exception 4 b. After step 3 if you hit back button you will see that there is a previous created activity

However if you were to use back button at step 2, and return to the app in any mean, it will work fine as there is only one activity in the navigation stack

Expected Behavior

It shouldn't create a new Activity on step 3

Actual Behavior

It created a new activity and I believe xamarin form is still referencing the first activity that got created rather than the second activity that is displayed. This causing exception.

Basic Information

  • Version with issue: 3.4.0.1008975
  • Last known good version: N/A
  • IDE: Visual Studio for MAC 3.0 (build 3001)
  • Platform Target Frameworks:
    • Android: 9.2.0.5
  • Android Support Library Version:
  • Nuget Packages: 4.8.2.5835
  • Affected Devices: one plus 6T (pie) the only device I tested on

Screenshots

N/A

Reproduction Link

https://1drv.ms/v/s!ApQ7q0pIhq0egVTJbOmdbkZmnZLl

Contributor guide