Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
lawrence_shaun_introducing_net_maui_build_and_deploy_crosspl.pdf
Скачиваний:
46
Добавлен:
26.06.2023
Размер:
5.15 Mб
Скачать

Chapter 14 Releasing Our Application

I am using net7.0 here because my application is built against .NET 7.0. If you are working against a different version of .NET, replace net7.0 with your chosen version. If you are unsure what version you are using, open your csproj file and look at the value inside the

<TargetFrameworks></TargetFrameworks> tags.

There are more required arguments to pass to the build, which involve signing key passwords and more, but this shows how easily this can be added to a set of automated steps that run each time code is committed or a merge request is opened.

You should also consider the testing that you added in Chapter 12 and see how this can also be incorporated into a CI environment.

dotnet test

This is far simpler than the publishing step. Running the tests in a CI environment really should be considered a critical set of criteria when building any application. The safety net that this provides in making sure your changes do not unintentionally break other bits of functionality alone makes it worthwhile.

Performance

Android has always been one of the slower platforms when building mobile applications. Don’t get me wrong; the applications can perform well on the higher-end devices, but Android devices come in a wide range of specifications, and typically in the business environment it is the cheaper devices that get bought in bulk and are expected to perform well. There are some concepts that you should consider when publishing your Android applications in order to boost the performance of your applications.

418

Chapter 14 Releasing Our Application

Startup Tracing

There are some extra steps that you can do in order to boost the startup times of your Android applications. Startup tracing essentially profiles an application when it starts to determine what libraries and other initializations are required so when you release the application it will benefit from a faster startup time. It is worth noting that boosting the startup time can result in an increase in application size so I recommend playing around with the settings to find the right balance for your application.

Microsoft has published two great blog posts on how startup tracing can be configured, the improvements it makes, and how the application can be affected:

•\ https://devblogs.microsoft.com/dotnet/dotnet-7- performance-improvements-in-dotnet-maui/

•\ https://devblogs.microsoft.com/xamarin/faster- startup-times-with-startup-tracing-on-android/

Image Sizes

One thing that can perform really poorly is the use of images that do not match the dimensions in which they need to be rendered on screen. For example, an image that displays at 100x100 pixels in the application really should be that size when supplied. If you were to render an image that was actually 300x300 pixels, it will not only look poor on the device due to scaling, but it will slow the application down. Plus, it involves storing an image that is bigger than really needed. Therefore, make sure that your images are correctly sized to gain the best experience when rendering them.

419

Chapter 14 Releasing Our Application

Use ofObservableCollection

A lot of common coding examples show how to bind an

ObservableCollection to the ItemsSource property of a control. This can have its uses, but it can have a big performance overhead. The reason is that each time an element is added to the collection, a UI update will be triggered because the control is monitoring for changes against the ObservableCollection. If you do not need live updating items in a collection, it is typically much faster to use a List and simple raise the

PropertyChanged event from INotifyPropertyChanged instead.

Let’s take a look at the code you added in Chapter 9 and see how it can be improved:

public ObservableCollection<Board> Boards { get; } = new ObservableCollection<Board>();

public void LoadBoards()

{

var boards = this.boardRepository.ListBoards();

foreach (var board in boards)

{

Boards.Add(board);

}

}

You can improve the performance of the above code by implementing it with a List as follows:

private IList<Board> boards;

public IList<Board> Boards

{

get => this.boards;

420