Suk*_*etu 6 android memory-leaks splash-screen xamarin
在我的 Xamarin android 应用程序中,当应用程序启动时,我会显示闪屏 3 秒。在此期间,我为创建 sqlite 表做后台工作,如果需要登录,从 web 加载用户信息。这些任务是使用异步方式完成的。
我为 splashactivity 分配了主题,在该主题中,我将背景分配为一个 37 KB 大小的 jpeg 文件,尺寸为 400*692。
3 秒后,我导航到我的 startActivity,在 SplashScreen 活动的 onDestroy 中,我将另一个主题分配给背景设置为 null 的窗口。但是,如果我对堆进行快照并在 MAT 中进行检查,它仍然显示具有泄漏嫌疑的 SplashActivity 具有 4.4 MB(占总堆的 13%)。我正在为 SplashActivity 以及样式附加代码。
请让我知道如何避免这种泄漏?
[Activity(Theme = "@style/Theme.SplashActivity", MainLauncher = true, NoHistory = true, ScreenOrientation = ScreenOrientation.Portrait)]
public class SplashScreen : BaseActivity
{
private AndroidDALProvider dalProvider;
public AndroidDALProvider DalProvider
{
get { return (dalProvider ?? (dalProvider = new AndroidDALProvider())); }
}
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
//Display Splash Screen for 3 Sec
AndroidDALProvider.InitializeTables();
Thread.Sleep(3000);
TablesCreated();
//Start Activity1 Activity
StartActivity(typeof(LoginActivity));
}
private void TablesCreated()
{
LoadData("283");
LoadData("284");
LoadData("248");
LoadData("249");
}
private void LoadData(string userID)
{
DalProvider.GetPatInfoWithID(userID,PatInfoLoadedFromSqlite);
}
private void PatInfoLoadedFromSqlite(PatientDemographicsDTOUI patientInfo, string patID)
{
if (patientInfo == null)
LoadDataFromInternet(patID);
}
private void LoadDataFromInternet(string userID)
{
//Check for internet connection
if (IsNetworkAvailable)
{
//set loggedinuser details for this user
try
{
ServiceProvider.GetPatDemographics(userID).ContinueWith(PatDemographicsReceived);
}
catch (Exception exception)
{
ShowMessage(ApplicationContext, exception.Message);
}
}
else
{
ShowMessage(ApplicationContext, "Network not available");
//ShowPatInfoScreen();
}
}
void PatDemographicsReceived(Task<PatientDemographicsDTO> patient)
{
if (patient != null)
{
//Fill the received data into local storage
DalProvider.AddPatInfoToStorage(patient.Result.GetUIModel(), PatInfoAddedToLocal);
}
}
private void PatInfoAddedToLocal(int obj)
{
}
protected override void OnDestroy()
{
dalProvider = null;
SetTheme(Resource.Style.Theme_SplashActivityNoBG);
base.OnDestroy();
}
}
Run Code Online (Sandbox Code Playgroud)
这是启动画面的样式。
<style name="Theme.SplashActivity" parent="CustomHoloTheme">
<item name="android:windowBackground">@drawable/splash</item>
<item name="android:windowNoTitle">true</item>
</style>
Run Code Online (Sandbox Code Playgroud)
这种风格我在飞溅活动的 OnDestroy 中应用
<style name="Theme.SplashActivityNoBG" parent="CustomHoloTheme">
<item name="android:windowBackground">@null</item>
<item name="android:windowNoTitle">true</item>
</style>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1214 次 |
| 最近记录: |