Properly closing SurfaceViews

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Properly closing SurfaceViews

Postby kdiddy » Sat Oct 17, 2009 2:30 pm

Does anyone know how to properly close an activity that is extending a surfaceview once it's no longer needed? I have my activity/surfaceview load a new activity but if the player hits the back button it throws an error. So I thought I'd call onDestroy in the new activity for the activity thats handling the surfaceview but it doesn't seem to close it. I overrided the back button as a temp fix but know it's bad code to not close an activity that isn't being used.

Here's what I was trying to do:


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.  
  3.  
  4. public class MainClass extends Activity {
  5.  
  6.  
  7.  
  8.           TheView sview;
  9.  
  10.  
  11.  
  12.           public void onCreate(Bundle savedInstanceState) {
  13.  
  14.                   super.onCreate(savedInstanceState)
  15.  
  16.                  setContentView(new sview(this));
  17.  
  18.           }
  19.  
  20.  
  21.  
  22.  
  23.  
  24.         public void onDestroy() {
  25.  
  26.               super.onDestroy();
  27.  
  28.               finish();
  29.  
  30.           }
  31.  
  32.  
  33.  
  34. }
  35.  
  36.  
  37.  
  38. public class NewClass extends Activity {
  39.  
  40.  
  41.  
  42.           MainClass mc;
  43.  
  44.  
  45.  
  46.           public void onCreate(Bundle savedInstanceState) {
  47.  
  48.                   super.onCreate(savedInstanceState)
  49.  
  50.                  setContentView(R.layout.main);
  51.  
  52.  
  53.  
  54.                  mc = new MainClass();
  55.  
  56.  
  57.  
  58.               mc.onDestroy();
  59.  
  60.           }
  61.  
  62.  
  63.  
  64.  
  65.  
  66.        
  67.  
  68. }
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4



Thanks,
K
Diddy
kdiddy
Junior Developer
Junior Developer
 
Posts: 19
Joined: Wed Apr 01, 2009 2:30 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Yahoo [Bot] and 6 guests