Main Activity
package itesm.mx.activity3_aboutmyself;
import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
private EditText input;
private Button b1;
private static final int PERRITO_CODE = 0;
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
input = findViewById(R.id.editText);
b1 = findViewById(R.id.button);
}
public void buttonTest(View v) {
Intent intent = new Intent(this, MenuActivity.class);
//startActivity(intent); startActivityForResult(intent, PERRITO_CODE);
}
}
Menu Activity / Perrito Activity
package mx.tec.jan21;
import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
public class PerritoActivity extends AppCompatActivity {
private TextView textito;
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_perrito);
textito = findViewById(R.id.textView);
Intent intent = getIntent();
String message = intent.getStringExtra("userName") + " age: " + intent.getIntExtra("age", 0);
textito.setText(message);
}
public void finishActivity(View v){
// go back sending info // use an intent! Intent intent = new Intent();
intent.putExtra("returnValue", "going back!");
setResult(Activity.RESULT_OK, intent);
finish();
}
}
Tips
On AndroidManifest.xml:
<activity android:name=".PerritoActivity"></activity>
Comments
Post a Comment