【问题标题】:xamarin android app crashes after multitasking多任务处理后xamarin android应用程序崩溃
【发布时间】:2018-04-03 12:56:21
【问题描述】:

我已经完成了我的第一个 xamarin android 移动应用程序。一切正常。我只有一个无法解决的问题,而且我无法使用 google 找到解决方案。

当我启动我的应用程序时,一切正常,但是当我按下主页按钮时,打开和关闭其他几个应用程序并返回应用程序时崩溃。此外,当我打开应用程序并关闭我的屏幕然后我将其重新打开并返回应用程序时,它就会崩溃。

除此之外,一切都很好,没有崩溃。 这种崩溃发生在模拟器和物理设备上。

在模拟器上发生这种情况时我得到的错误是:

android.content.ActivityNotFoundException: Unable to find explicit activity class {com.name.appname/com.name.android.publish.OverlayActivity}; have you declared this activity in your AndroidManifest.xml?

如果可能,如何解决这个问题?

编辑: AndoirdManifest.xml 文件如下所示:

 <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.name.tournamentorganizer" android:installLocation="auto" android:versionName="1.1" android:versionCode="2">
  <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="27" />
  <uses-permission android:name="android.permission.INTERNET" />
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  <application android:allowBackup="true" android:label="@string/app_name" android:icon="@drawable/icon11" android:name="android.app.Application" android:debuggable="true">
    <activity android:label="Create new tournament" android:theme="@android:style/Theme.Material.Light" android:name="md57e31db4bba5ea713128b60ee6f3868c2.createNewTournament" />
    <activity android:label="Tournament Organizer" android:theme="@android:style/Theme.Material.Light" android:name="md57e31db4bba5ea713128b60ee6f3868c2.MainActivity">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
    </activity>
    <activity android:label="Add new players" android:theme="@android:style/Theme.Material.Light" android:name="md5a2089f5b800658a06dd2a11fca5a1f83.addNewPlayers" />
    <activity android:label="addGoalScorer" android:theme="@android:style/Theme.Material.Light" android:name="md54d075dbf8b437fae408fa9e57e2203ba.addGoalScorer" />
    <activity android:label="All fixtures and results" android:theme="@android:style/Theme.Material.Light" android:name="md54d075dbf8b437fae408fa9e57e2203ba.allFixturesAndResults" />
    <activity android:label="Players database" android:theme="@android:style/Theme.Material.Light" android:name="md54d075dbf8b437fae408fa9e57e2203ba.allPlayersActivity" />
    <activity android:label="knockout4Players" android:name="md54d075dbf8b437fae408fa9e57e2203ba.knockout4Players" />
    <activity android:label="League" android:theme="@android:style/Theme.Material.Light" android:name="md54d075dbf8b437fae408fa9e57e2203ba.leagueType" />
    <activity android:label="My tournaments" android:theme="@android:style/Theme.Material.Light" android:name="md54d075dbf8b437fae408fa9e57e2203ba.myTournaments" />
    <activity android:label="About" android:theme="@android:style/Theme.Material.Light" android:name="md54d075dbf8b437fae408fa9e57e2203ba.settings" />
    <activity android:label="Player Info" android:theme="@android:style/Theme.Material.Light" android:name="md54d075dbf8b437fae408fa9e57e2203ba.stats" />
    <activity android:label="table" android:theme="@android:style/Theme.Material.Light" android:name="md54d075dbf8b437fae408fa9e57e2203ba.table" />
    <activity android:label="Top scorers" android:theme="@android:style/Theme.Material.Light" android:name="md54d075dbf8b437fae408fa9e57e2203ba.topScorerActivity" />
    <activity android:label="Winners" android:theme="@android:style/Theme.Material.Light" android:name="md54d075dbf8b437fae408fa9e57e2203ba.winnersActivity" />
    <activity android:label="winnersAllTimeActivity" android:theme="@android:style/Theme.Material.Light" android:name="md54d075dbf8b437fae408fa9e57e2203ba.winnersAllTimeActivity" />
    <provider android:name="mono.MonoRuntimeProvider" android:exported="false" android:initOrder="2147483647" android:authorities="com.name.tournamentorganizer.mono.MonoRuntimeProvider.__mono_init__" />
    <!--suppress ExportedReceiver-->
    <receiver android:name="mono.android.Seppuku">
      <intent-filter>
        <action android:name="mono.android.intent.action.SEPPUKU" />
        <category android:name="mono.android.intent.category.SEPPUKU.com.name.tournamentorganizer" />
      </intent-filter>
    </receiver>
    <meta-data android:name="android.support.VERSION" android:value="25.4.0" />
  </application>
</manifest> 

编辑2:

我有带广告和不带广告的应用版本。没有广告的就没有这个问题。有广告的确实有问题,所以广告在某种程度上是有问题的。我正在使用 startapp 广告。

【问题讨论】:

    标签: c# xamarin.android


    【解决方案1】:

    您可能不会使用[Activity] 代码装饰

    [Activity]
    internal class YourActivity: Activity {}
    

    【讨论】:

    • 这是不可能的,否则它会在调用活动的那一刻崩溃
    • 我不确定你的意思是什么。我所有的活动都是这样的: [Activity(Theme = "theme", Label = "name", MainLauncher = true)] public class MainActivity : Activity {}
    【解决方案2】:

    如果你所有的活动都有

    [Activity(Theme = "theme", Label = "name", MainLauncher = true)]
    

    将 MainLauncher 参数设置为 true 你会遇到麻烦。

    Xamarin 使用 Activity 注释来配置/生成 AndroidManifest.xml

    您是否包含了一个 MainApplication 类,也带有 [Application] 属性标记?看着你的清单,我很惊讶地看到这条线

    <application android:allowBackup="true" android:label="@string/app_name" android:icon="@drawable/icon11" android:name="android.app.Application" android:debuggable="true">
    

    使用 android:name="android.app.Application"。我希望看到带有 md5 哈希的东西(即 md5xxx.MainApplication - 或任何您的 Application 类的名称)

    更改应用程序类后可能需要清理和重建

    【讨论】:

    • 那是错误的。 MainLauncher = true 部分仅按应有的方式设置在主要活动上。我将 android 清单文件添加到问题中。
    • 我不太明白你的意思。我在哪里可以找到 MainApplication 类?我该如何改变它?这个问题真的很烦人,到处都找不到解决办法。
    • 我已经用重要信息编辑了我的问题 - 这一切都是因为 startapp 广告而发生的。
    • 好的,如果这与 startapp 相关,您可能应该就此提出一个新问题,因为上述答案不相关。你是如何绑定startapp sdk的?通过带有绑定库的 .jar 文件?
    • 与返回广告有关。我必须更改屏幕旋转选项才能使其正常工作。无论如何,我决定切换到 admob,所以现在一切正常。
    猜你喜欢
    • 2013-05-07
    • 1970-01-01
    • 2015-12-05
    • 1970-01-01
    • 1970-01-01
    • 2021-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多