activity one .java page
package com.example.viraj.intent; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button button = (Button) findViewById(R.id.gotobutton); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(getApplicationContext(), Secondpage.class); intent.putExtra("keytosend", "dat kept here to send");
intent.putExtra("value",123);startActivity(intent); } }); } }
second activity page
package com.example.viraj.intent; import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.widget.TextView; public class Secondpage extends AppCompatActivity { private TextView textView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_secondpage); textView = (TextView) findViewById(R.id.text_secondpage); Bundle name_bundel = getIntent().getExtras();if (name_bundel != null) {//ye string value ke liye he-------------------- String name_string = name_bundel.getString("keytosend");//ye integer type ki value ke liye he-------------------int intvalue=name_bundel.getInt("value");textView.setText("MESSAGE IS"+name_string+"values is "+intvalue);
} } }
0 comments:
Post a Comment