PowenKo> Android > Activity > back and result

February 6, 2012   ·   0 Comments

Screen Shot 2012-02-06 at 11.21.19 AM

sample code:

Tutorial_Activity_Activity_backPage

package com.powenko;








import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;




public class Tutorial_Activity_Activity_backPageActivity extends Activity {
	 int requestCode;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button b1 = (Button) findViewById(R.id.button1);
        b1.setOnClickListener(new Button.OnClickListener()
        {
          public void onClick(View v)
          {
           
            Intent intent = new Intent();
        	  intent.setClass(Tutorial_Activity_Activity_backPageActivity.this, page2.class);
        	  
        	  Bundle bundle=new Bundle();
        	  bundle.putInt("intvlaue", 1);
        	  bundle.putString("Web", "www.powenko.com");        	
        	  intent.putExtras(bundle);
       
        	  startActivityForResult(intent,0);
        //	  startActivity(intent);
        //	  Tutorial_Activity_Activity_backPageActivity.this.finish();
          }
        });
    }
    
    
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        Log.d("CheckStartActivity","onActivityResult and resultCode = "+resultCode);
        // TODO Auto-generated method stub
        super.onActivityResult(requestCode, resultCode, data);
        if(resultCode==RESULT_OK){
            Toast.makeText(this, "Pass", Toast.LENGTH_LONG).show();
            Bundle bundle2=data.getExtras();
            String t_page2Result=bundle2.getString("page2Result");
            




            TextView t_textView_title = (TextView)findViewById(R.id.textView1);
            t_textView_title.setText(t_page2Result);
            
            
        }
        else{
            Toast.makeText(this, "Fail", Toast.LENGTH_LONG).show();
        }
    }
    
}
package com.powenko;



import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;



public class page2 extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.page2layout);
        Bundle bundle= this.getIntent().getExtras();
        int t_value=bundle.getInt("intvlaue");
        String t_web=bundle.getString("Web");
        

        TextView t_textView_title = (TextView)findViewById(R.id.textView1);
        t_textView_title.setText(t_web+ t_value);
        
        
        Button b1 = (Button) findViewById(R.id.button1);
        b1.setOnClickListener(new Button.OnClickListener()
        {
          public void onClick(View v)
          {
        	  FunBack();
             
          }
        });
        
        
    }
    
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
        	FunBack();
            
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
    public void FunBack(){
      Intent intent = page2.this.getIntent();
      Bundle bundle= intent.getExtras();

   	  bundle.putString("page2Result", "this info is from page2"); 
   	  intent.putExtras(bundle);
         
   	  page2.this.setResult(RESULT_OK, intent);
   	  page2.this.finish();
    }
    
    
}
shareShare on FacebookShare on Google+Share on LinkedInEmail this to someonePrint this pageBuffer this pageDigg thisFlattr the authorShare on RedditPin on PinterestShare on StumbleUponShare on TumblrTweet about this on Twitter

By


Readers Comments (0)


You must be logged in to post a comment.

PowenKo’s Online Store

powenko_arduinoBook
Android7

Amazon

adsbygoogle

Recent Posts

Categories

Amazon