Im very new to xamarin and created download Notification. It works for the most time but sometime the app get a fetal error and shutdown after the creation of the Notification.

I only get this rapport, which i have no idee how to trace.

=================================================================
    Native Crash Reporting
=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================
06-02 05:39:28.296 E/mono-rt (16761): /proc/self/maps:
06-02 05:39:28.296 E/mono-rt (16761): 12c00000-16f40000 rw-p 00000000 00:01 25459                              /dev/ashmem/dalvik-main space (region space)_4473_4473 (deleted)
06-02 05:39:28.296 E/mono-rt (16761): 16f40000-172c0000 rw-p 04340000 00:01 25459                              /dev/ashmem/dalvik-main space (region space)_4473_4473 (deleted)
06-02 05:39:28.296 E/mono-rt (16761): 172c0000-17340000 ---p 046c0000 00:01 25459                              /dev/ashmem/dalvik-main space (region space)_4473_4473 (deleted)
06-02 05:39:28.296 E/mono-rt (16761): 17340000-173c0000 rw-p 04740000 00:01 25459                              /dev/ashmem/dalvik-main space (region space)_4473_4473 (deleted)
06-02 05:39:28.296 E/mono-rt (16761): 173c0000-18380000 ---p 047c0000 00:01 25459                              /dev/ashmem/dalvik-main space (region space)_4473_4473 (deleted)
06-02 05:39:28.296 E/mono-rt (16761): 18380000-183c0000 rw-p 05780000 00:01 25459                              /dev/ashmem/dalvik-main space (region space)_4473_4473 (deleted)
06-02 05:39:28.297 E/mono-rt (16761): 183c0000-18400000 ---p 057c0000 00:01 25459                              /dev/ashmem/dalvik-main space (region space)_4473_4473 (deleted)

=================================================================
    Basic Fault Adddress Reporting
=================================================================
Memory around native instruction pointer (0x6f51ecb678):0x6f51ecb668  00 1c 40 b9 c0 03 5f d6 fd 7b bf a9 fd 03 00 91  [email protected]_..{......
0x6f51ecb678  08 20 40 b9 a8 00 c8 37 88 01 e0 37 00 00 40 f9  . @[email protected]
0x6f51ecb688  fd 7b c1 a8 c0 03 5f d6 60 08 00 b0 01 0a 00 f0  .{...._.`.......
0x6f51ecb698  03 0a 00 f0 00 24 06 91 21 80 08 91 63 8c 0a 91  .....$..!...c...

No native Android stacktrace (see debuggerd output).

Here is how i start the service

  Methods.OnVideoDownload += new Action<Manager.Models.Container.YoutubeFileDownloadItem>((video) =>
    {
        if (!ObjectCacher.DownloadingFiles.ContainsKey(video.VideoId))
        {
            ObjectCacher.DownloadingFiles.Add(video.VideoId, video);
            var intent = new Intent(this, typeof(FileService));
            intent.PutExtra(FileService.URL, new AppManager().GetVideoStreamUrl(video.VideoId, 18));
            intent.PutExtra(FileService.Title, video.Title);
            intent.PutExtra(FileService.DirectoryName, Path.Combine(Methods.LocalMusicFolder, video.Playlist));
            intent.PutExtra(FileService.FileName, video.GenerateLocalPath());

            if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
            {
                var servive = this.StartForegroundService(intent);
            }
            else
            {
                this.StartService(intent);
            }
        }
    });

And here is onstartCommand which after the return of return StartCommandResult.Sticky; the application shut down

 public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId)
    {
        PendingIntent pendingIntent = PendingIntent.GetActivity(MainActivity.Current, 0, intent, 0);
        var url = intent.GetStringExtra(URL);
        var fileName = intent.GetStringExtra(FileName);
        var directory = intent.GetStringExtra(DirectoryName);
        var title = intent.GetStringExtra(Title);

        intent.AddFlags(ActivityFlags.ClearTop);
        var nb = NotificationHelper.GetNotification1(GetString(Resource.String.Downloading) + " " + title, GetString(Resource.String.DownloadProgress), pendingIntent);


        if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
        {
            StartForeground(NotificationId, nb.Build());
        }


        var _downlodFile = new DownlodFile(url, directory, fileName, new Action<int>((procent) =>
        {
            nb.SetContentText("")
            .SetContentTitle(GetString(Resource.String.Downloading) + $" ({procent}%) " + title)
            .SetProgress(100, procent, false);
            NotificationHelper.Notify(NotificationId, nb);
        }), new Action(async () =>
        {
            try
            {
                await Methods.DownloadCompleted(fileName);
            }
            catch (Exception ex)
            {
            }
            nb.SetOnlyAlertOnce(false).SetProgress(0, 0, false)
            .SetContentText(GetString(Resource.String.Finished));
            await Task.Delay(100);
            NotificationHelper.Notify(NotificationId, nb);
            ObjectCacher.RandomIdCacher.Remove(NotificationId);
            nb.Dispose();
            NotificationHelper.Dispose();
            if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
            {
                StopForeground(true);
            }

        }), new Action<Exception>((e) =>
        {
            nb.SetProgress(0, 0, false).SetContentText("Error: Something went wrong.\n Please try agen later.");
            NotificationHelper.Notify(NotificationId, nb);
            ObjectCacher.RandomIdCacher.Remove(NotificationId);
            nb.Dispose();
            NotificationHelper.Dispose();
            if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
            {
                StopForeground(true);
            }
        }));
        _downlodFile.Download();
        NotificationHelper.Notify(NotificationId, nb);
        return StartCommandResult.Sticky;
    }
}

Any idee of what causing this problem or even how to trace it.

0 Answers