๋ฐ์ํ
Notice
Recent Posts
Recent Comments
Link
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- serverless
- ์คํธ๋ฆผ๋ฆฟ ๊ธฐ๋ณธ
- MySQL
- ์๋ฐ์คํฌ๋ฆฝํธ ๊ณต๋ถ
- ์น๋์๋ณด๋ ์ ์
- java
- ์คํธ๋ฆผ๋ฆฟ
- JavaScript
- Matplotlib ๊ธฐ์ด
- streamlit
- ์๋๋ก์ด๋ ์คํ๋์ค
- ํ์ด์ฌ๊ณต๋ถ
- db
- ํ์ด์ฌ
- ์๋ฐ์ด๋ณด
- ์๋๋ก์ด๋ ์ฑ ๊ฐ๋ฐ
- ํ๋ค์ค
- RESTful API
- ์๋ฐ๊ธฐ์ด
- Streamlit๊ธฐ๋ณธ
- Pandas
- ์๋ฐ๊ณต๋ถ
- ์๋ฐ
- ์๋ฐ์คํฌ๋ฆฝํธ
- Streamlit๊ธฐ์ด
- ํ๋ค์ค๊ณต๋ถ
- ์๋ฐํ๋ก๊ทธ๋๋ฐ
- Android
- ๋ฐ์ดํฐ๋ฒ ์ด์ค
- ์น๋์๋ณด๋ ๊ธฐ์ด
Archives
- Today
- Total
ruriruriya
[Android] ์๋๋ก์ด๋ - ๊ฐ์ฒด ์ ์ฒด ๋ฐ์ดํฐ๋ฅผ ํ๊บผ๋ฒ์ ๋ค๋ฅธ ์กํฐ๋นํฐ์ ๋ณด๋ด๊ธฐ Serializable (๋ฐ์ดํฐ ์ง๋ ฌํ) ๋ณธ๋ฌธ
๐คAndroid/Java
[Android] ์๋๋ก์ด๋ - ๊ฐ์ฒด ์ ์ฒด ๋ฐ์ดํฐ๋ฅผ ํ๊บผ๋ฒ์ ๋ค๋ฅธ ์กํฐ๋นํฐ์ ๋ณด๋ด๊ธฐ Serializable (๋ฐ์ดํฐ ์ง๋ ฌํ)
๋ฃจ๋ฆฌ์ผใ 2024. 1. 8. 15:20๋ฐ์ํ
์๋ฐ์์ Serializable๋ ๋ฐ์ดํฐ๋ฅผ ์ง๋ ฌํํ๋ ์ธํฐํ์ด์ค๋ค.
์ด๋ฅผ ํตํด ๊ฐ์ฒด์ ์ํ๋ฅผ ๋ฐ์ดํธ ์คํธ๋ฆผ์ผ๋ก ๋ณํํ์ฌ ๋คํธ์ํฌ๋ฅผ ํตํด ์ ์กํ๊ฑฐ๋ ํ์ผ๋ก ์ ์ฅํ ์ ์๋ค.
์๋๋ก์ด๋ ์ฑ ๊ฐ๋ฐ์์๋ Serializable ์ธํฐํ์ด์ค๋ฅผ ์ฌ์ฉํ์ฌ ๊ฐ์ฒด๋ฅผ ์ง๋ ฌํํ ์ ์๋ค.
1. ํ๋ฉด ์ค๊ณ
2. Data.java Serializable ์์
import java.io.Serializable;
public class Data implements Serializable {
public String name;
public int age;
public Data() {
}
public Data(String name, int age) {
this.name = name;
this.age = age;
}
}
3. MainActivity.java
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import com.sunny.serializable.model.Data;
public class MainActivity extends AppCompatActivity {
TextView txtMain;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtMain = findViewById(R.id.txtMain);
txtMain.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// Intent ๊ฐ์ฒด ์์ฑ
Intent intent = new Intent(MainActivity.this, SubActivity.class);
// Data ํด๋์ค ๊ฐ์ฒด ์์ฑ
Data data = new Data("ํ๊ธธ๋",30);
// Data ํด๋์ค์ ์ง๋ ฌํ ๋ฐ์ดํฐ ์ ๋ฌ
intent.putExtra("data",data);
startActivity(intent);
}
});
}
}
4. SubActivity.java
import android.os.Bundle;
import android.widget.TextView;
import com.sunny.serializable.model.Data;
public class SubActivity extends AppCompatActivity {
TextView txtName;
TextView txtAge;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sub);
txtName = findViewById(R.id.txtName);
txtAge = findViewById(R.id.txtAge);
// Data ํด๋์ค ๊ฐ์ฒด ์์ฑ, data
Data data = new Data();
// ์ง๋ ฌํ๋ Data ํด๋์ค์ ๊ฒ์ฒด๋ฅผ getSerializableExtra ๋ฉ์๋๋ก ์ ๋ฌ ๋ฐ์.
data = (Data) getIntent().getSerializableExtra("data");
txtName.setText(data.name);
txtAge.setText(data.age + "์ด ์
๋๋ค.");
}
}
5. MainActivity์์ SubActivity๋ก ์คํํ๋ฉด
๋ฐ์ํ