owo #1
@ -3,23 +3,51 @@ package me.jj97181818.ch08_multiactivity;
|
||||
import android.content.Intent;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
TextView tvPath;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
tvPath = findViewById(R.id.tv_path1);
|
||||
|
||||
run(getIntent());
|
||||
}
|
||||
|
||||
private void run(Intent intent) {
|
||||
tvPath.setText(intent.getCharSequenceExtra("path"));
|
||||
if (tvPath.getText().equals("")) {
|
||||
tvPath.setText("1");
|
||||
}
|
||||
else {
|
||||
tvPath.setText(tvPath.getText() + " -> 1");
|
||||
}
|
||||
}
|
||||
|
||||
public void goBack (View v) {
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra("path", tvPath.getText());
|
||||
setResult(RESULT_OK, intent);
|
||||
|
||||
finish();
|
||||
}
|
||||
|
||||
public void gotoSecondActivity(View v) {
|
||||
Intent it = new Intent(this, SecondActivity.class);
|
||||
startActivity(it);
|
||||
it.putExtra("path", tvPath.getText());
|
||||
startActivityForResult(it, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
run(data);
|
||||
}
|
||||
}
|
||||
|
@ -1,24 +1,48 @@
|
||||
package me.jj97181818.ch08_multiactivity;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class SecondActivity extends AppCompatActivity {
|
||||
TextView tvPath;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_second);
|
||||
|
||||
tvPath = findViewById(R.id.tv_path2);
|
||||
|
||||
run(getIntent());
|
||||
}
|
||||
|
||||
private void run(Intent intent) {
|
||||
tvPath.setText(intent.getCharSequenceExtra("path"));
|
||||
tvPath.setText(tvPath.getText() + " -> 2");
|
||||
}
|
||||
|
||||
public void goBack (View v) {
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra("path", tvPath.getText());
|
||||
setResult(RESULT_OK, intent);
|
||||
|
||||
finish();
|
||||
}
|
||||
|
||||
public void gotoThirdActivity(View v) {
|
||||
Intent it = new Intent(this, ThirdActivity.class);
|
||||
startActivity(it);
|
||||
it.putExtra("path", tvPath.getText());
|
||||
startActivityForResult(it, 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
run(data);
|
||||
}
|
||||
}
|
||||
|
@ -1,24 +1,48 @@
|
||||
package me.jj97181818.ch08_multiactivity;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class ThirdActivity extends AppCompatActivity {
|
||||
TextView tvPath;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_third);
|
||||
|
||||
tvPath = findViewById(R.id.tv_path3);
|
||||
|
||||
run(getIntent());
|
||||
}
|
||||
|
||||
private void run(Intent intent) {
|
||||
tvPath.setText(intent.getCharSequenceExtra("path"));
|
||||
tvPath.setText(tvPath.getText() + " -> 3");
|
||||
}
|
||||
|
||||
public void goBack (View v) {
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra("path", tvPath.getText());
|
||||
setResult(RESULT_OK, intent);
|
||||
|
||||
finish();
|
||||
}
|
||||
|
||||
public void gotoFirstActivity(View v) {
|
||||
Intent it = new Intent(this, MainActivity.class);
|
||||
startActivity(it);
|
||||
it.putExtra("path", tvPath.getText());
|
||||
startActivityForResult(it, 3);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
run(data);
|
||||
}
|
||||
}
|
||||
|
@ -6,24 +6,8 @@
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".MainActivity">
|
||||
|
||||
<Button
|
||||
android:id="@+id/button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:onClick="gotoSecondActivity"
|
||||
android:text="開啟活動2"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/button5"
|
||||
app:layout_constraintVertical_bias="0.125" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView"
|
||||
android:id="@+id/tv_name1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="20dp"
|
||||
@ -33,17 +17,45 @@
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/button5"
|
||||
<TextView
|
||||
android:id="@+id/tv_path1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="200dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:text="TextView"
|
||||
app:layout_constraintBottom_toTopOf="@+id/btn_back1"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/tv_name1" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn_back1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="164dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:onClick="goBack"
|
||||
android:text="結束活動1"
|
||||
app:layout_constraintBottom_toTopOf="@+id/btn_start1"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn_start1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginBottom="164dp"
|
||||
android:onClick="gotoSecondActivity"
|
||||
android:text="開啟活動2"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
|
||||
</android.support.constraint.ConstraintLayout>
|
@ -6,24 +6,8 @@
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".SecondActivity">
|
||||
|
||||
<Button
|
||||
android:id="@+id/button2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:onClick="goBack"
|
||||
android:text="回到活動1"
|
||||
app:layout_constraintBottom_toTopOf="@+id/button3"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_bias="0.848" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView2"
|
||||
android:id="@+id/tv_name2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="20dp"
|
||||
@ -33,8 +17,35 @@
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_path2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:text="TextView"
|
||||
app:layout_constraintBottom_toTopOf="@+id/btn_back2"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/tv_name2" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/button3"
|
||||
android:id="@+id/btn_back2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="164dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:onClick="goBack"
|
||||
android:text="回到活動1"
|
||||
app:layout_constraintBottom_toTopOf="@+id/btn_start2"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn_start2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
|
@ -7,7 +7,7 @@
|
||||
tools:context=".ThirdActivity">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView3"
|
||||
android:id="@+id/tv_name3"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="20dp"
|
||||
@ -17,28 +17,40 @@
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/button4"
|
||||
<TextView
|
||||
android:id="@+id/tv_path3"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="88dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:text="TextView"
|
||||
app:layout_constraintBottom_toTopOf="@+id/btn_back3"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/tv_name3" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn_back3"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="164dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:onClick="goBack"
|
||||
android:text="回到活動2"
|
||||
app:layout_constraintBottom_toTopOf="@+id/button6"
|
||||
app:layout_constraintBottom_toTopOf="@+id/btn_start3"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/button6"
|
||||
android:id="@+id/btn_start3"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginBottom="163dp"
|
||||
android:layout_marginBottom="164dp"
|
||||
android:onClick="gotoFirstActivity"
|
||||
android:text="開啟活動1"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
|
Reference in New Issue
Block a user