質問編集履歴

2

すみません。この投稿用に作ったこのソースでのコーディングミスで、本物は正しくコーディングしていました。確認不足で申し訳ございません。

2022/10/07 02:35

投稿

sakHi
sakHi

スコア4

test CHANGED
File without changes
test CHANGED
@@ -122,7 +122,7 @@
122
122
  android:layout_width="match_parent"
123
123
  android:layout_height="match_parent"
124
124
  android:background="#20FF0000"
125
- tools:context=".MainActivity">
125
+ tools:context=".NextActivity">
126
126
 
127
127
  <TextView
128
128
  android:id="@+id/txtNext"

1

反応ありがとうございます。再現するソースを貼りました。よろしくお願いいたします。

2022/10/07 00:33

投稿

sakHi
sakHi

スコア4

test CHANGED
File without changes
test CHANGED
@@ -16,9 +16,156 @@
16
16
  ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@XXXXX
17
17
 
18
18
  ### 該当のソースコード
19
+ ```AndroidManifest.xml
20
+ <?xml version="1.0" encoding="utf-8"?>
21
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android"
22
+ xmlns:tools="http://schemas.android.com/tools"
23
+ package="com.example.sample">
19
24
 
25
+ <application
26
+ android:allowBackup="true"
27
+ android:dataExtractionRules="@xml/data_extraction_rules"
28
+ android:fullBackupContent="@xml/backup_rules"
29
+ android:icon="@mipmap/ic_launcher"
30
+ android:label="@string/app_name"
31
+ android:roundIcon="@mipmap/ic_launcher_round"
32
+ android:supportsRtl="true"
33
+ android:theme="@style/Theme.Sample"
34
+ tools:targetApi="31">
35
+ <activity
36
+ android:name=".MainActivity"
37
+ android:exported="true">
38
+ <intent-filter>
20
- ((Button)findViewById( R.id.btnNxt )).setOnClickListener( view -> startActivity( new Intent(this, 遷移先Activityクラス名.class ) ) );
39
+ <action android:name="android.intent.action.MAIN" />
21
40
 
41
+ <category android:name="android.intent.category.LAUNCHER" />
42
+ </intent-filter>
43
+ </activity>
44
+ <activity
45
+ android:name=".NextActivity"
46
+ android:exported="false">
47
+ </activity>
48
+ </application>
49
+
50
+ </manifest>
51
+ ```
52
+ ```activity_main.xml
53
+ <?xml version="1.0" encoding="utf-8"?>
54
+ <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
55
+ xmlns:tools="http://schemas.android.com/tools"
56
+ xmlns:app="http://schemas.android.com/apk/res-auto"
57
+ android:layout_width="match_parent"
58
+ android:layout_height="match_parent"
59
+ tools:context=".MainActivity">
60
+
61
+ <TextView
62
+ android:id="@+id/txtHello"
63
+ android:layout_width="wrap_content"
64
+ android:layout_height="wrap_content"
65
+ android:text="Hello World!"
66
+ app:layout_constraintBottom_toBottomOf="parent"
67
+ app:layout_constraintStart_toStartOf="parent"
68
+ app:layout_constraintEnd_toEndOf="parent"
69
+ app:layout_constraintTop_toTopOf="parent" />
70
+
71
+ <Button
72
+ android:id="@+id/btnNext"
73
+ android:layout_width="wrap_content"
74
+ android:layout_height="wrap_content"
75
+ android:text="NEXT"
76
+ app:layout_constraintBottom_toBottomOf="parent"
77
+ app:layout_constraintStart_toEndOf="@id/txtHello"
78
+ app:layout_constraintEnd_toEndOf="parent"
79
+ app:layout_constraintTop_toBottomOf="@id/txtHello" />
80
+
81
+ <Button
82
+ android:id="@+id/btnExit"
83
+ android:layout_width="wrap_content"
84
+ android:layout_height="wrap_content"
85
+ android:text="EXIT"
86
+ app:layout_constraintBottom_toBottomOf="parent"
87
+ app:layout_constraintStart_toStartOf="parent"
88
+ app:layout_constraintEnd_toStartOf="@id/txtHello"
89
+ app:layout_constraintTop_toBottomOf="@id/txtHello" />
90
+
91
+ </androidx.constraintlayout.widget.ConstraintLayout>
92
+ ```
93
+ ```MainActivity.java
94
+ package com.example.sample;
95
+
96
+ import androidx.appcompat.app.AppCompatActivity;
97
+
98
+ import android.content.Intent;
99
+ import android.os.Bundle;
100
+ import android.widget.Button;
101
+
102
+ public class MainActivity extends AppCompatActivity{
103
+
104
+ @Override
105
+ protected void onCreate( Bundle savedInstanceState ){
106
+ super.onCreate( savedInstanceState );
107
+ setContentView( R.layout.activity_main );
108
+
109
+ // (ボタン)NEXT
110
+ findViewById(R.id.btnNext).setOnClickListener( view -> startActivity( new Intent( this, NextActivity.class ) ) );
111
+
112
+ // (ボタン)EXIT
113
+ findViewById(R.id.btnExit).setOnClickListener( view -> finishAndRemoveTask() );
114
+ }
115
+ }
116
+ ```
117
+ ```activity_next.xml
118
+ <?xml version="1.0" encoding="utf-8"?>
119
+ <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
120
+ xmlns:tools="http://schemas.android.com/tools"
121
+ xmlns:app="http://schemas.android.com/apk/res-auto"
122
+ android:layout_width="match_parent"
123
+ android:layout_height="match_parent"
124
+ android:background="#20FF0000"
125
+ tools:context=".MainActivity">
126
+
127
+ <TextView
128
+ android:id="@+id/txtNext"
129
+ android:layout_width="wrap_content"
130
+ android:layout_height="wrap_content"
131
+ android:text="Next Acivity."
132
+ app:layout_constraintBottom_toBottomOf="parent"
133
+ app:layout_constraintStart_toStartOf="parent"
134
+ app:layout_constraintEnd_toEndOf="parent"
135
+ app:layout_constraintTop_toTopOf="parent" />
136
+
137
+ <Button
138
+ android:id="@+id/btnBack"
139
+ android:layout_width="wrap_content"
140
+ android:layout_height="wrap_content"
141
+ android:text="BACK"
142
+ app:layout_constraintBottom_toBottomOf="parent"
143
+ app:layout_constraintStart_toStartOf="parent"
144
+ app:layout_constraintEnd_toStartOf="@id/txtNext"
145
+ app:layout_constraintTop_toBottomOf="@id/txtNext" />
146
+
147
+ </androidx.constraintlayout.widget.ConstraintLayout>
148
+ ```
149
+ ```NextActivity.java
150
+ package com.example.sample;
151
+
152
+ import android.content.Intent;
153
+ import android.os.Bundle;
154
+
155
+ import androidx.appcompat.app.AppCompatActivity;
156
+
157
+ public class NextActivity extends AppCompatActivity{
158
+
159
+ @Override
160
+ protected void onCreate( Bundle savedInstanceState ){
161
+ super.onCreate( savedInstanceState );
162
+ setContentView( R.layout.activity_next );
163
+
164
+ // (ボタン)BACK
165
+ findViewById(R.id.btnBack).setOnClickListener( view -> finish() );
166
+ }
167
+ }
168
+ ```
22
169
  ### 試したこと
23
170
 
24
171
  this を getApplicationContext() に変えてみたぐらいです。。