Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does my android apps activitie reopen when I close my app
    text
    copied!<p>I have been trying to solve this problem for a while now and I am sure there is a way to solve this error/problem but I haven't found that yet.</p> <p>The problem I am having is once I exit the app via the back button or home button it closes but then reopens one of my activities which was opened before.</p> <p>Do I need to close my activities once I press one of those buttons and how would I go around doing that.</p> <p>Here is the code for my main activity that opens my other activity...</p> <pre><code>package com.togdem.tunnels; import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.MotionEvent; import android.view.View; import android.view.View.OnTouchListener; import android.widget.ImageView; import android.widget.SeekBar; import android.widget.Toast; import android.widget.SeekBar.OnSeekBarChangeListener; public class TunnelsActivity extends Activity { int vo = 2; String mla = ""; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ImageView p_btn = (ImageView) findViewById(R.id.imageView1); p_btn.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View view, MotionEvent event) { Intent myIntent2 = new Intent(view.getContext(), Cgt.class); startActivity(myIntent2); return false; } }); SeekBar skb = (SeekBar) findViewById(R.id.seekBar1); try { InputStream in = openFileInput("sa.txt"); if (in != null) { InputStreamReader input = new InputStreamReader(in); BufferedReader buffreader = new BufferedReader(input); mla = ""; String line = new String(); line = buffreader.readLine(); mla += line; Toast msg = Toast.makeText(getBaseContext(), "Loaded Saved Data", Toast.LENGTH_LONG); msg.show(); in.close(); skb.setProgress(Integer.parseInt(mla.toString())); } else{} } catch(Exception e){} skb.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { public void onProgressChanged(SeekBar event, int value, boolean sb) { vo = value; } public void onStartTrackingTouch(SeekBar event) { } public void onStopTrackingTouch(SeekBar event) { try { OutputStreamWriter out = new OutputStreamWriter(openFileOutput("sa.txt", 0)); out.write(Integer.toString(vo)); out.close(); } catch (IOException e) { } Toast msg = Toast.makeText(getBaseContext(), "Set Sensitivity to: " + Integer.toString(vo), Toast.LENGTH_LONG); msg.show(); } }); } } </code></pre> <p>And here is the code for the activity I am trying to open...</p> <pre><code>package com.togdem.tunnels; import java.io.OutputStreamWriter; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.util.Log; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.View; import android.view.View.OnTouchListener; import android.widget.ImageView; public class Cgt extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView( R.layout.cgame ); ImageView btn1 = (ImageView) findViewById(R.id.btn_c); ImageView btn2 = (ImageView) findViewById(R.id.btn_h); btn1.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View view, MotionEvent event) { try { OutputStreamWriter out = new OutputStreamWriter(openFileOutput("spd.txt", 0)); out.write("4"); out.close(); } catch (java.io.IOException e) {} Intent myIntent = new Intent(view.getContext(), TunnelsSpA.class); myIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); startActivity(myIntent); finish(); return false; } }); btn2.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View view, MotionEvent event) { try { OutputStreamWriter out = new OutputStreamWriter(openFileOutput("spd.txt", 0)); out.write("6"); out.close(); } catch (java.io.IOException e) {} Intent myIntent = new Intent(view.getContext(), TunnelsSpA.class); myIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); startActivity(myIntent); finish(); return false; } }); } public boolean onKeyDown(int KeyCode, KeyEvent event) { if (KeyCode == KeyEvent.KEYCODE_BACK); { onStop(); } if (KeyCode == KeyEvent.KEYCODE_HOME); { onStop(); } return super.onKeyDown(KeyCode, event); } protected void onStop() { finish(); Log.d("Stopping...", "Stopping the activity"); } } </code></pre> <p>Thanks for any help you can give me,</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload