java - 为什么 Intent 在 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" />
// ...
解决方案
推荐阅读
- python - 如何在 seaborn legend 中选择和排序值
- c# - 编辑导入的excel文件的datagridview的值
- powerbi - PowerBI DAX Calculation:按月移动平均分组计算
- css - 隐藏在 Quasar 中其他组件后面的粘性浮动操作按钮
- git - Git Push 包括我的路径目录(BitBucket)
- jenkins - Jenkins 仪表板中的上次成功和上次失败列未正确更新
- c - C - 简单链表删除包含'k'的第一个元素
- python - 如何使用“unittest”从测试类中杀死 Python 程序?
- azure - Azure 数据工厂:Web 和 Webhook 活动的安全性
- jquery - Django:如何将表单加载到当前的 html 页面