質問編集履歴

4

訂正

2016/09/03 14:43

投稿

syosinsya12
syosinsya12

スコア69

test CHANGED
File without changes
test CHANGED
@@ -58,7 +58,7 @@
58
58
 
59
59
 
60
60
 
61
- if (back = true){
61
+ if (back == true){
62
62
 
63
63
  finish();
64
64
 
@@ -120,7 +120,7 @@
120
120
 
121
121
 
122
122
 
123
- if (back = true){
123
+ if (back == true){
124
124
 
125
125
  finish();
126
126
 
@@ -170,6 +170,10 @@
170
170
 
171
171
  editor.commit();
172
172
 
173
+
174
+
175
+ finish();
176
+
173
177
  }
174
178
 
175
179
  });

3

訂正

2016/09/03 14:43

投稿

syosinsya12
syosinsya12

スコア69

test CHANGED
File without changes
test CHANGED
@@ -6,7 +6,137 @@
6
6
 
7
7
  okのところの処理の書き方が分かりません。
8
8
 
9
+
10
+
9
11
  ```
12
+
13
+ public class MainActivity extends AppCompatActivity {
14
+
15
+
16
+
17
+ boolean back;
18
+
19
+
20
+
21
+ @Override
22
+
23
+ protected void onCreate(Bundle savedInstanceState) {
24
+
25
+ super.onCreate(savedInstanceState);
26
+
27
+ setContentView(R.layout.activity_main);
28
+
29
+
30
+
31
+ back = false;
32
+
33
+
34
+
35
+ SharedPreferences.Editor editor = preferences.edit();
36
+
37
+ editor.putBoolean("finish", back);
38
+
39
+ editor.commit();
40
+
41
+
42
+
43
+
44
+
45
+ }
46
+
47
+
48
+
49
+ @Override
50
+
51
+ public void onResume(){
52
+
53
+ super.onResume();
54
+
55
+ SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
56
+
57
+ back = preferences.getBoolean("finish", false);
58
+
59
+
60
+
61
+ if (back = true){
62
+
63
+ finish();
64
+
65
+ }
66
+
67
+
68
+
69
+ }
70
+
71
+ public void start(View view){
72
+
73
+ Intent intent = new Intent(this,Game.class);
74
+
75
+ startActivity(intent);
76
+
77
+ }
78
+
79
+ }
80
+
81
+ コード
82
+
83
+ ```
84
+
85
+ ```
86
+
87
+ public class Game extends AppCompatActivity {
88
+
89
+
90
+
91
+ public final static String SCORE = "com.sample.SCORE";
92
+
93
+
94
+
95
+ boolean back;
96
+
97
+
98
+
99
+ @Override
100
+
101
+ protected void onCreate(Bundle savedInstanceState) {
102
+
103
+ super.onCreate(savedInstanceState);
104
+
105
+ setContentView(R.layout.activity_game);
106
+
107
+ }
108
+
109
+
110
+
111
+ @Override
112
+
113
+ public void onResume (){
114
+
115
+ super.onResume();
116
+
117
+ SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
118
+
119
+ back = preferences.getBoolean("finish", false);
120
+
121
+
122
+
123
+ if (back = true){
124
+
125
+ finish();
126
+
127
+ }
128
+
129
+
130
+
131
+ }
132
+
133
+ コード
134
+
135
+ ```
136
+
137
+ ```
138
+
139
+ public class Result extends AppCompatActivity {
10
140
 
11
141
 
12
142
 
@@ -32,7 +162,7 @@
32
162
 
33
163
 
34
164
 
35
- SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences();
165
+ SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(Result.this);
36
166
 
37
167
  SharedPreferences.Editor editor = preferences.edit();
38
168
 

2

訂正

2016/09/03 14:36

投稿

syosinsya12
syosinsya12

スコア69

test CHANGED
File without changes
test CHANGED
@@ -26,15 +26,19 @@
26
26
 
27
27
  public void onClick(DialogInterface dialogInterface, int i) {
28
28
 
29
- MainActivity mainActivity = new MainActivity();
29
+
30
30
 
31
- Game game = new Game();
31
+ boolean back = true;
32
32
 
33
- mainActivity.finish1();
34
33
 
35
- game.finish2();
36
34
 
35
+ SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences();
36
+
37
+ SharedPreferences.Editor editor = preferences.edit();
38
+
39
+ editor.putBoolean("finish", back);
40
+
37
- finish3();
41
+ editor.commit();
38
42
 
39
43
  }
40
44
 

1

訂正

2016/09/03 13:25

投稿

syosinsya12
syosinsya12

スコア69

test CHANGED
File without changes
test CHANGED
@@ -20,9 +20,31 @@
20
20
 
21
21
  alertdialog.setMessage("アプリを終了しますか?");
22
22
 
23
- alertdialog.setPositiveButton("OK", );
23
+ alertdialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
24
+
25
+ @Override
26
+
27
+ public void onClick(DialogInterface dialogInterface, int i) {
28
+
29
+ MainActivity mainActivity = new MainActivity();
30
+
31
+ Game game = new Game();
32
+
33
+ mainActivity.finish1();
34
+
35
+ game.finish2();
36
+
37
+ finish3();
38
+
39
+ }
40
+
41
+ });
24
42
 
25
43
  alertdialog.setNegativeButton("NO",null);
44
+
45
+
46
+
47
+
26
48
 
27
49
  AlertDialog alertDialog = alertdialog.create();
28
50