java - MainActivty 未在 Nougat 和 Oreo 上启动

标签 java android android-layout

在 Android 9 设备 (Lineage OS 16) 中运行该应用程序时,它可以正常工作。但当我尝试在牛轧糖或奥利奥等设备上打开它时,它只显示空白的白色 Activity 。 (注意:在 Android 9(Lineage OS)中,我的白色空白屏幕仅持续 1 或 2 秒,但在 Nougat 和 Oreo 中,它卡在空白屏幕)。我尝试启动其他 Activity 作为启动器 Activity 和其他 Activity ,但应启动 MainActivity 类才能使其他 Activity 正常工作。我不知道错误是在布局设计中还是在 Java 类中(我认为错误可能不在 Java 类中,因为该应用程序在 Android 9 设备上完美运行!!)。这里我提供了 xml 布局和 Java 类。

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
    android:id="@+id/drawer_layout"

    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
  xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <LinearLayout
            android:id="@+id/ll_ads"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:orientation="horizontal" />
        <RelativeLayout
            android:id="@+id/track_info"
            android:background="#ff0000"
            android:visibility="gone"
            android:layout_width="fill_parent"
            android:layout_height="@dimen/track_info_layout_height"
            android:layout_above="@+id/ll_ads">
            <LinearLayout
                android:background="@color/bottom_control_background"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">
                <com.makeramen.roundedimageview.RoundedImageView
                    android:layout_gravity="center_vertical"
                    android:id="@+id/artwork_min"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="4.0dip"
                    android:src="@drawable/default_artwork"
                    android:scaleType="fitXY"
                    android:contentDescription="@string/album_artwork" />
                <RelativeLayout
                    android:padding="@dimen/content_padding"
                    android:layout_width="0.0dip"
                    android:layout_height="fill_parent"
                    android:layout_weight="1.0">
                    <TextView
                        android:textSize="16.0sp"
                        android:textStyle="bold"
                        android:textColor="#ffffff"
                        android:ellipsize="end"
                        android:id="@+id/song_title"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:singleLine="true"
                        android:layout_alignParentTop="true" />
                    <TextView
                        android:textSize="14.0sp"
                        android:textColor="#ffffff"
                        android:ellipsize="end"
                        android:id="@+id/song_artist"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="4.0dip"
                        android:singleLine="true"
                        android:layout_below="@+id/song_title" />
                </RelativeLayout>
                <LinearLayout
                    android:id="@+id/quick_controls"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent">
                    <ImageButton
                        android:id="@+id/quick_prev"
                        android:background="?selectableItemBackgroundBorderless"
                        android:layout_width="wrap_content"
                        android:layout_height="fill_parent"
                        android:src="@drawable/btn_prev"
                        android:scaleType="center"
                        android:contentDescription="@string/prev" />
                    <ImageButton
                        android:id="@+id/quick_play_pause_toggle"
                        android:background="?selectableItemBackgroundBorderless"
                        android:layout_width="wrap_content"
                        android:layout_height="fill_parent"
                        android:src="@drawable/btn_play"
                        android:scaleType="center"
                        android:contentDescription="@string/play" />
                    <ImageButton
                        android:id="@+id/quick_next"
                        android:background="?selectableItemBackgroundBorderless"
                        android:layout_width="wrap_content"
                        android:layout_height="fill_parent"
                        android:src="@drawable/btn_next"
                        android:scaleType="center"
                        android:contentDescription="@string/next" />
                </LinearLayout>
            </LinearLayout>
            <com.musicplayer.players9.musicsamsung.free2018.widgets.ProgressBar
                android:id="@+id/progress_bar"
                android:padding="0.0dip"
                android:layout_width="fill_parent"
                android:layout_height="2.0dip"
                android:layout_alignParentTop="true"
                app:progressColor="?colorAccent" />
        </RelativeLayout>
        <FrameLayout
            android:id="@+id/container"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_above="@+id/track_info" />
    </RelativeLayout>
    <android.support.design.widget.NavigationView
        android:layout_gravity="start"
        android:id="@+id/navigation_view"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        app:menu="@menu/navigation" />
</android.support.v4.widget.DrawerLayout>

Java 类 Lint to Java Class

最佳答案

不可能...我不会把它写成答案;一旦他读了,我就会删除它。 但如果逐行进行并进行相同的更改后,它也会得到解决

Stop coding thousands of lines in your mainsctivity

它不是所有代码、逻辑和操作所在的地方...!!

What is mainActivity for then,,,??

据我所知,只有 100 行代码

What that 100 lines of code should do?

检查 Android 版本,如果上面的 Marshmallow 询问下面的权限则不执行任何操作。并在主线程上启动服务或启动另一个线程来执行操作和任务..!!

解决方案:

  1. 通过在创建新项目时在 android studio 中准备好的导航项目示例代码来创建一个新项目
  2. 忘记编码。不要编写任何一行代码,保持原样。
  3. 在所有模拟器(例如 5.0、6.0、7.0、8.0、9.0)上检查它
  4. 它会起作用,而且它必须起作用..!!
  5. 现在在 mainactivity 中只需获取权限即可。
  6. 无论您需要执行什么操作,都可以在后台线程中执行。
  7. 是的,我知道您会问我也想访问主用户界面...
  8. 请观看并执行此视频等示例代码...请不要避免观看它...不要欺骗自己... Very simple demonstration of performing operations in android projects
  9. 完成后,再次将代码从以前的应用移至此新结构
  10. 这需要时间......,但这是正确的做法。

就是这样。它。

A i know this is not the answer ..., I know this should not be the error as well

关于java - MainActivty 未在 Nougat 和 Oreo 上启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52463129/

相关文章:

java - 处理 UDP 不可靠性

java - 如何调用静态类中存在的方法?

Java:解析和写入xml文件

Android:使用不安全的 ssl 证书

Android Drawable 与它的布局不匹配

java - 日期验证不起作用

java - 动态添加 ImageView 并设置其位置

android - 如何要求 android.permission.CALL_PHONE 但仍安装在平板电脑上?

Android 用户界面规模

java - 微调器不显示所选项目