How to remove previous View when call next view ?

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

How to remove previous View when call next view ?

Postby JamesAndroid » Thu Dec 10, 2009 10:03 am

Hi guys.

I am a new developer for android.

I used following code to change the View :

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. import android.app.Activity;
  3.  
  4. import android.content.Intent;
  5.  
  6. import android.os.Bundle;
  7.  
  8. import android.view.View;
  9.  
  10. import android.widget.Button;
  11.  
  12.  
  13.  
  14. public class FirstActivity extends Activity {
  15.  
  16.     /** Called when the activity is first created. */
  17.  
  18.         Intent intend = null;
  19.  
  20.        
  21.  
  22.     @Override
  23.  
  24.     public void onCreate(Bundle savedInstanceState) {
  25.  
  26.         intend = new Intent();
  27.  
  28.         super.onCreate(savedInstanceState);
  29.  
  30.         setContentView(R.layout.main);
  31.  
  32.         Button button1 = (Button) findViewById(R.id.btnnext);
  33.  
  34.         button1.setOnClickListener(new View.OnClickListener() {
  35.  
  36.                  public void onClick(View view) {
  37.  
  38.                          intend.setClass(FirstActivity.this, SecondActivity.class);
  39.  
  40.                          startActivity(intend);
  41.  
  42.                 }
  43.  
  44.        });
  45.  
  46.     }
  47.  
  48. }
  49.  
  50.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


This code cann't remove previous View when call SecondActivity.

I don't know how to remove previous View.

Please advice. guys.

Thanks in advance.
JamesAndroid
Junior Developer
Junior Developer
 
Posts: 23
Joined: Mon Dec 07, 2009 7:23 am

Top

Postby qlimax » Thu Dec 10, 2009 11:29 am

you mean destroy the first activity?
you have to call

finish();

after you have started the second activity.

bye
¯`·.¸¸.><((((º>¯`·.¸¸. ><((((º>
User avatar
qlimax
Master Developer
Master Developer
 
Posts: 271
Joined: Mon Aug 31, 2009 10:54 am
Location: Swiss

Postby JamesAndroid » Fri Dec 11, 2009 3:54 am

Thanks. I got it.
Works fine.
JamesAndroid
Junior Developer
Junior Developer
 
Posts: 23
Joined: Mon Dec 07, 2009 7:23 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 6 guests