为什么在 Android 中没有显示意图?

问题描述

如果我从(启动 PIN.class Activity)开始一个 Intent,布局将不会显示。为什么 Toast 会立即显示在每个 Android 上,但我的 PIN.class 布局却没有?

我认为这与我的 PIN.class 有关。更改 setPriority 也不能解决问题。或者可能是,我们在 Runnable 函数中启动了必要的代码

谢谢!

// PIN.java
public class PIN extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestwindowFeature(Window.FEATURE_NO_TITLE);
        // Star Layout HERE 
        setContentView(R.layout.activity_settings);

    }
    
}

// MainActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {

    Handler handler = new Handler(Looper.getMainLooper());
        Runnable runnableCode = new Runnable() {
            
        @Override
        public void run() {
                
            Toast.makeText(context,"got toasted",Toast.LENGTH_LONG).show();

                Intent intent = new Intent(context,PIN.class);

                IntentFilter filter = new IntentFilter(String.valueOf(intent));
                filter.setPriority(1000);// what you want to set
                
                    /**
                    * ...starting the important Intent
                    **/
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                        startForegroundService(intent);
                    } 
                    
                    else {
                        startService(intent);
                    }
                    
                    startActivity(intent);
        }
    };
}

// activity_settings.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <TextView
        android:id="@+id/textViewPinSettingsHeadline"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/setPin_label"
        tools:layout_editor_absoluteX="62dp"
        tools:layout_editor_absoluteY="60dp"
        android:textSize="30dp"
        android:textColor="@color/colorPrimary"
        />

    <TextView
        android:id="@+id/textViewPinSettings"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Old PIN: "
        tools:layout_editor_absoluteX="62dp"
        tools:layout_editor_absoluteY="60dp" />

    <EditText
        android:id="@+id/oldpininput"
        android:hint="1234"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="number"
        tools:layout_editor_absoluteX="154dp"
        tools:layout_editor_absoluteY="60dp" />

    <TextView
        android:id="@+id/textViewPinSettings"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="New PIN: "
        tools:layout_editor_absoluteX="62dp"
        tools:layout_editor_absoluteY="129dp" />

    <EditText
        android:id="@+id/newpininput"
        android:hint="0"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="number"
        tools:layout_editor_absoluteX="154dp"
        tools:layout_editor_absoluteY="129dp" />

    <Button
        android:id="@+id/buttonSetPin"
        android:layout_width="match_parent"
        android:layout_height="55dp"

        android:text="save PIN"
        app:layout_constraintBottom_toBottomOf="parent" />

</LinearLayout>

// AndroidManifest.xml
// ...
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
// ...

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...