Android应用程序崩溃的银河S8仅边沿

问题描述:

我建立它采用网页视图中xamarin的应用程序,我已经测试了他们的许多设备,如银河S7边缘。我想其中的原因不工作是因为边缘网屏的。但是,它在S7 Edge上正常工作,但在我尝试过的S8 Edge设备上,它们会立即崩溃。Android应用程序崩溃的银河S8仅边沿

有只有两个,我使用类:

MainActivity:

namespace APPNAME.Android 
{ 
[Activity(Label = "APPNAME", Icon = "@drawable/icon", MainLauncher = 
false, 
    ConfigurationChanges = ConfigChanges.ScreenSize | 
    ConfigChanges.Orientation)] 

public class MainActivity : Activity 
{ 
    WebView web_view; 
    //private bool appeared; 
    public class HelloWebViewClient : WebViewClient 
    { 
     public override bool ShouldOverrideUrlLoading(WebView view, string 
     url) 
     { 
      view.LoadUrl(url); 
      return false; 
     } 
    } 

    protected override void OnCreate(Bundle bundle) 
    { 
     Window.RequestFeature(WindowFeatures.NoTitle); 
     base.OnCreate(bundle); 
     // Set our view from the "main" layout resource 
     SetContentView(Resource.Layout.Main); 

     web_view = FindViewById<WebView>(Resource.Id.webview); 
     web_view.Settings.JavaScriptEnabled = true; 
     web_view.SetWebViewClient(new HelloWebViewClient()); 

     web_view.LoadUrl("http://link.com"); 
    } 

    public override bool OnKeyDown(Keycode keyCode, KeyEvent e) 
    { 
     if (keyCode == Keycode.Back && web_view != null) 
     { 
      try 
      { 
       if (web_view.CanGoBack()) 
       { 
        Log.Debug("*", "Allow browser back"); 
        // Toast.MakeText(this, "Going back", 
        ToastLength.Short).Show(); 
        web_view.GoBack(); 
        return true; 
       } 
      } 
      catch (Exception ex) 
      { 
       Log.Error("*", ex.Message); 
      } 
     } 

     { 
      //Log.Error("StackOv20erflow", "Null webview..."); 
      //StartActivity(typeof(MainActivity)); 
      //Finish(); 
      OnBackPressed(); 
     } 
     //Log.Debug("*", "Back button blocked"); 
     //Toast.MakeText(this, "Back button blocked", 
     ToastLength.Short).Show(); 
     return false; 
    } 

    public override void OnBackPressed() 
    { 
     Intent startMain = new Intent(Intent.ActionMain); 
     startMain.AddCategory(Intent.CategoryHome); 
     startMain.SetFlags(ActivityFlags.NewTask); 
     StartActivity(startMain); 

    } 

} 

} 

闪屏:

namespace APPNAME.Android 
{ 
[Activity(Theme = "@style/MyTheme.Splash", MainLauncher = true, NoHistory = 
true)] 
public class SplashActivity : AppCompatActivity 
{ 
    static readonly string TAG = "X:" + typeof(SplashActivity).Name; 

    public override void OnCreate(Bundle savedInstanceState, 
    PersistableBundle persistentState) 
    { 
     base.OnCreate(savedInstanceState, persistentState); 
     Log.Debug(TAG, "SplashActivity.OnCreate"); 
    } 

    // Launches the startup task 
    protected override void OnResume() 
    { 
     base.OnResume(); 
     Task startupWork = new Task(() => { SimulateStartup(); }); 
     startupWork.Start(); 
    } 

    // Simulates background work that happens behind the splash screen 
    async void SimulateStartup() 
    { 
     //Log.Debug(TAG, "Performing some startup work that takes a bit of 
     time."); 
     //await Task.Delay(1000); // Simulate a bit of startup work. 
     //Log.Debug(TAG, "Startup work is finished - starting 
     MainActivity."); 
     //StartActivity(new Intent(Application.Context, 
     typeof(MainActivity))); 
     await Task.Delay(4000); 
     var intent = new Intent(this, typeof(MainActivity)); 
     intent.AddFlags(ActivityFlags.ClearTop | ActivityFlags.NewTask); 
     StartActivity(intent); 
    } 
    } 
} 

清单:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
android:versionName="1.0.0.8" package="APPNAME.android" 
android:installLocation="auto" android:versionCode="8"> 
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="25" /> 
<application android:label="APPNAME" android:icon="@drawable/Icon" 
android:debuggable="false"></application> 
<uses-permission android:name="android.permission.INTERNET" /> 
</manifest> 

不知道从哪里开始修复发行因为我不知道这是什么原因。

任何帮助,将不胜感激!

+0

事件和处理程序请包括logcat的输出也崩溃 –

+0

什么在Logcat中? – SushiHangover

+0

您是否安装了碰撞记者?如果没有,请添加一个;-) – SushiHangover

避免使用async void除非在事件处理程序中。而且也从来不创建一个new Task和使用task.Start

参考Async/Await - Best Practices in Asynchronous Programming

不过我劝你创建的SplashActivity

public class SplashActivity : AppCompatActivity { 

    static readonly string TAG = "X:" + typeof(SplashActivity).Name; 

    public override void OnCreate(Bundle savedInstanceState, PersistableBundle persistentState) { 
     base.OnCreate(savedInstanceState, persistentState); 
     Log.Debug(TAG, "SplashActivity.OnCreate"); 
    } 

    // Launches the startup task 
    private event EventHandler Starting = delegate { } 
    protected override void OnResume() { 
     base.OnResume(); 
     //subscribe to event 
     Starting += Activity_Starting; 
     //raise event 
     Starting (this, EventArgs.Empty); 
    } 

    // Simulates background work that happens behind the splash screen 
    async void Activity_Starting(object sender, EventArgs e) { 
     //unsubscribe 
     Starting -= Activity_Starting; 
     //and carry on 
     //Log.Debug(TAG, "Performing some startup work that takes a bit of time."); 
     //await Task.Delay(1000); // Simulate a bit of startup work. 
     //Log.Debug(TAG, "Startup work is finished - starting MainActivity."); 
     //StartActivity(new Intent(Application.Context, typeof(MainActivity))); 
     await Task.Delay(4000); 
     var intent = new Intent(this, typeof(MainActivity)); 
     intent.AddFlags(ActivityFlags.ClearTop | ActivityFlags.NewTask); 
     StartActivity(intent); 
    } 
    } 
} 
+0

只是一个谨慎的词来实施这个人..如果你+ =每个的onResume事件处理程序,那么你会继续乘以只需导航回到此活动即可运行此次数。 –

+0

@ Le-royStaines即使在事件处理程序中取消订阅? (顺便说一下)。通过这种立场,即使没有像OP那样的事件也会发生同样的情况。思考? – Nkosi

+0

哎呦,我错过了你取消订阅处理程序。虽然这是最优雅的方式吗?如果有人在其他地方举办活动而没有订阅呢? –