Back from activity problem

Put your problem here if it does not fit any of the other categories.

Back from activity problem

Postby T0mA » Fri Mar 11, 2011 8:44 pm

So i got 2 acrivitys i want to go back from the sub A to the main A. I try with the back Key but it closes the full application, then i tried to make a Back button, with finish() but it does the same, can some one help me? Here are the 2 activitys:
Code: Select all
package org.example.sudoku;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.content.Intent;

public class Sudoku extends Activity implements OnClickListener {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
     // Set up click listeners for all the buttons
       
        View exitButton = findViewById(R.id.exit_button);
        exitButton.setOnClickListener(this);
        View scanButton = findViewById(R.id.scan_button);
        scanButton.setOnClickListener(this);
        View editButton = findViewById(R.id.about_button);
        editButton.setOnClickListener(this);
       
    }
   public void onClick(View v) {
      switch (v.getId()) {
      case R.id.scan_button:
         Intent intent = new Intent("com.google.zxing.client.android.SCAN");
         intent.putExtra("com.google.zxing.client.android.SCAN.SCAN_MODE", "QR_CODE_MODE");
         startActivityForResult(intent, 0);
      break;
      case R.id.about_button:
         Intent aboutint = new Intent(this.getApplicationContext(),About.class);
         startActivityForResult(aboutint, 0);
      case R.id.exit_button:
         finish();
      break;
   

               }
            }
   

   
   public void onActivityResult(int requestCode, int resultCode, Intent intent) {
       if (requestCode == 0) {
           if (resultCode == RESULT_OK) {
               String contents = intent.getStringExtra("SCAN_RESULT");
               String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
               // Handle successful scan
            

           } else if (resultCode == RESULT_CANCELED) {
               // Handle cancel
           }
       }
   }

}

   







I open the second activity with the About button, and here is the code for the second one:
Code: Select all
package org.example.sudoku;


   import android.app.Activity;

   import android.os.Bundle;
   import android.view.View;
   import android.view.View.OnClickListener;
   import android.widget.*;
   import android.content.Intent;
   public class About extends Activity implements OnClickListener{
   @Override
   protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.about);
   View backButton =findViewById(R.id.back_button);
   backButton.setOnClickListener(this);

   

   }
   public void onClick(View v) {
      switch (v.getId()) {

      case R.id.back_button:
         finish();
      break;
   

               }
            }
   

   
}
T0mA
Freshman
Freshman
 
Posts: 5
Joined: Fri Mar 04, 2011 10:05 pm

Top

Re: Back from activity problem

Postby T0mA » Fri Mar 11, 2011 8:44 pm

Hmm i just changed the second Activity's theme to dialog , so the second activity window is now smaller , and i saw that right after i push the about button , and the second activity comes up the main A. is closed.So when i push back or use finish() of course the app is closed... What could be the problem??
T0mA
Freshman
Freshman
 
Posts: 5
Joined: Fri Mar 04, 2011 10:05 pm

Re: Back from activity problem

Postby T0mA » Fri Mar 11, 2011 10:17 pm

fixed it, just missed a break; up there... :D
T0mA
Freshman
Freshman
 
Posts: 5
Joined: Fri Mar 04, 2011 10:05 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 18 guests