์ „์ฒด ๊ธ€ 396

6. ์•กํ‹ฐ๋น„ํ‹ฐ ์ˆ˜๋ช…์ฃผ๊ธฐ (Life Cycle)

์•กํ‹ฐ๋น„ํ‹ฐ์˜ ๋Œ€ํ‘œ์ ์ธ ์ƒํƒœ์ •๋ณด ์‹คํ–‰(Running) -ํ™”๋ฉด์ƒ์— ์•กํ‹ฐ๋น„ํ‹ฐ๊ฐ€ ๋ณด์ด๋ฉด์„œ ์‹คํ–‰๋˜์–ด ์žˆ๋Š” ์ƒํƒœ -์•กํ‹ฐ๋น„ํ‹ฐ ์Šคํƒ์˜ ์ตœ์ƒ์œ„์— ์žˆ์œผ๋ฉฐ ํฌ์ปค์Šค๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์Œ ์ผ์‹œ ์ค‘์ง€(Paused) -์‚ฌ์šฉ์ž์—๊ฒŒ ๋ณด์ด๊ธฐ๋Š” ํ•˜์ง€๋งŒ ๋‹ค๋ฅธ ์•กํ‹ฐ๋น„ํ‹ฐ๊ฐ€ ์œ„์— ์žˆ์–ด ํฌ์ปค์Šค๋ฅผ ๋ฐ›์ง€ ๋ชปํ•˜๋Š” ์ƒํƒœ. -๋Œ€ํ™”์ƒ์ž๊ฐ€ ์œ„์— ์žˆ์–ด ์ผ๋ถ€๊ฐ€ ๊ฐ€๋ ค์ ธ ์žˆ๋Š” ๊ฒฝ์šฐ์— ํ•ด๋‹น ์ค‘์ง€(Stopped) -๋‹ค๋ฅธ ์•กํ‹ฐ๋น„ํ‹ฐ์— ์˜ํ•ด ์™„์ „ํžˆ ๊ฐ€๋ ค์ ธ ๋ณด์ด์ง€ ์•Š๋Š” ์ƒํƒœ ์ด๋ ‡๊ฒŒ ์•กํ‹ฐ๋น„ํ‹ฐ์˜ ์ƒํƒœ์ •๋ณด๊ฐ€ ๋ณ€ํ™”ํ•˜๋Š”๊ฒƒ์„ ์•กํ‹ฐ๋น„ํ‹ฐ์˜ ์ˆ˜๋ช…์ฃผ๊ธฐ(Life Cycle)๋ผ๊ณ  ํ•˜๋ฉฐ ์•กํ‹ฐ๋น„ํ‹ฐ๊ฐ€ ์ฒ˜์Œ ๋งŒ๋“ค์–ด์ง„ ํ›„ ์—†์–ด์งˆ๋•Œ๊นŒ์ง€ ์ƒํƒœ๊ฐ€ ๋ณ€ํ™”ํ•˜๋ฉด์„œ ๊ฐ๊ฐ์— ํ•ด๋‹นํ•˜๋Š” ๋ฉ”์†Œ๋“œ๊ฐ€ ์ž๋™์œผ๋กœ ํ˜ธ์ถœ๋จ onCreate() -์•กํ‹ฐ๋น„ํ‹ฐ๊ฐ€ ์ฒ˜์Œ์— ๋งŒ๋“ค์–ด์กŒ์„๋•Œ ํ˜ธ์ถœ๋จ -ํ™”๋ฉด์— ๋ณด์ด๋Š” ๋ทฐ๋“ค์˜ ์ผ๋ฐ˜์ ์ธ ์ƒํƒœ๋ฅผ ์„ค์ •ํ•˜๋Š” ๋ถ€๋ถ„ -์ด์ „ ์ƒํƒœ..

Dev_Study/Android 2018.01.26

5. ์•กํ‹ฐ๋น„ํ‹ฐ ๊ฐ„์— ๋ฐ์ดํ„ฐ ์ „๋‹ฌํ•˜๊ธฐ

์•กํ‹ฐ๋น„ํ‹ฐ๊ฐ„์— ๋ฐ์ดํ„ฐ๋ฅผ ์ „๋‹ฌํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉํ•˜๋Š” ๋ฒˆ๋“ค๊ฐ์ฒด๋Š” ์ธํ…ํŠธ ์•ˆ์— ๋“ค์–ด์žˆ๊ธฐ ๋•Œ๋ฌธ์— putExtra(), getExtra()๋ฅผ ์ด์šฉํ•ด ๋„ฃ๊ฑฐ๋‚˜ ๋ณผ ์ˆ˜ ์žˆ๋‹ค ๊ธฐ๋ณธ์ ์œผ๋กœ ๊ธฐ๋ณธ๋ฐ์ดํ„ฐํƒ€์ž…(Primitive Data Type)๋งŒ์„ ์ง€์›ํ•˜๋ฏ€๋กœ ๋ฌธ์ž์—ด์ด๋‚˜ ์ •์ˆ˜์™€ ๊ฐ™์€ ๋ฐ์ดํ„ฐ๋ฅผ ํ‚ค์™€ ๋ฐ์ดํ„ฐ ๊ฐ’์˜ ์Œ์œผ๋กœ ๋งŒ๋“ค์–ด ๋„ฃ๋Š”๋‹ค [Reference] Intent putExtra(String name, String value) Intent putExtra(String name, int value) Intent putExtra(String name, boolean value) String getStringExtra(String name) int getIntExtra(String name, int defaultValue) boolean ..

Dev_Study/Android 2018.01.26

4. ํ”Œ๋ž˜๊ทธ(Flag)

ํ”Œ๋ž˜๊ทธ(Flag) ์•กํ‹ฐ๋น„ํ‹ฐ๊ฐ€ ๋™์ž‘ํ•˜๋Š” ๋ฐฉ์‹์„ ์„ค์ • [Reference] FLAG_ACTIVITY_SINGLE_TOP ์•กํ‹ฐ๋น„ํ‹ฐ๋ฅผ ์ƒ์„ฑํ• ๋•Œ ์ด๋ฏธ ์ƒ์„ฑ๋œ ์•กํ‹ฐ๋น„ํ‹ฐ๊ฐ€ ์žˆ์œผ๋ฉด ์žฌ์‚ฌ์šฉ FLAG_ACTIVITY_NO_HISTORY ์ฒ˜์Œ์ดํ›„์— ์‹คํ–‰๋œ ์•กํ‹ฐ๋น„ํ‹ฐ๋Š” ์•กํ‹ฐ๋น„ํ‹ฐ ์Šคํƒ์— ์ถ”๊ฐ€๋˜์ง€ ์•Š๋Š”๋‹ค ์‚ฌ์šฉ์ž์—๊ฒŒ ํ•œ๋ฒˆ๋งŒ ํ™”๋ฉด์„ ๋ณด์—ฌ์ฃผ๊ณ ์‹ถ์„๋•Œ ์‚ฌ์šฉ FLAG_ACTIVITY_CLEAR_TOP ์ž์‹ ๋ณด๋‹ค ์œ„์—์žˆ๋Š” ๋‹ค๋ฅธ ์•กํ‹ฐ๋น„ํ‹ฐ๋ฅผ ๋ชจ๋‘ ์ข…๋ฃŒ์‹œํ‚ด [Reference] public void onNewIntent(Intent intent) ์•กํ‹ฐ๋น„ํ‹ฐ๊ฐ€ ์ด๋ฏธ ๋ฉ”๋ชจ๋ฆฌ์ƒ์˜ ๊ฐ์ฒด๋กœ ๋งŒ๋“ค์–ด์ ธ์žˆ๋Š” ๊ฒฝ์šฐ ์•กํ‹ฐ๋น„ํ‹ฐ๋ฅผ ๋‹ค์‹œ ์”Œ์šฐ๋”๋ผ๋„ onCreate()๋ฉ”์†Œ๋“œ๊ฐ€ ํ˜ธ์ถœ๋˜์ง€ ์•Š์œผ๋ฏ€๋กœ onNewIntent()๋ฉ”์†Œ๋“œ๋ฅผ ์žฌ์ •์˜ํ•ด ์‚ฌ์šฉํ•ด์•ผํ•œ๋‹ค onNewIntent()๋ฉ”์†Œ๋“œ..

Dev_Study/Android 2018.01.26

2. ํ™”๋ฉด ๊ฐ„ ์ด๋™

์•ˆ๋“œ๋กœ์ด๋“œ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๊ตฌ์„ฑํ•˜๋Š” ๋„ค๊ฐ€์ง€ ๊ตฌ์„ฑ์š”์†Œ -์•กํ‹ฐ๋น„ํ‹ฐ -์„œ๋น„์Šค -๋ธŒ๋กœ๋“œ์บ์ŠคํŠธ ์ˆ˜์‹ ์ž -๋‚ด์šฉ ์ œ๊ณต์ž [Reference] startActivityForResult(Intent intent, int requestCode) ๋‹จ์ˆœํžˆ ๋„์šฐ๋Š”๊ฒƒ์ด ์•„๋‹ˆ๋ผ ์–ด๋–ค ์•กํ‹ฐ๋น„ํ‹ฐ๋ฅผ ๋„์šด๊ฒƒ์ธ์ง€, ๊ทธ๋ฆฌ๊ณ  ๋„์› ๋˜ ์•กํ‹ฐ๋น„ํ‹ฐ๋กœ๋ถ€ํ„ฐ์˜ ์‘๋‹ต์„ ๋ฐ›์•„ ์ฒ˜๋ฆฌํ• ๋•Œ [Reference] protected void onActivityResult(int requestCode, int resultCode, Intent intent) ๋„์› ๋˜ ์•กํ‹ฐ๋น„ํ‹ฐ์—์„œ ๋Œ์•„์˜ฌ๋•Œ ์ž๋™ํ˜ธ์ถœ ๋„์› ๋˜ ์•กํ‹ฐ๋น„ํ‹ฐ๊ฐ€ ์‘๋‹ต์„ ๋ณด๋‚ด์˜ค๋ฉด ๊ทธ ์‘๋‹ต์„ ์ฒ˜๋ฆฌํ•˜๋Š” ์—ญํ•  [Reference] setResult(int resultCode, Intent intent) ํ˜„์žฌ ์•กํ‹ฐ๋น„ํ‹ฐ๋ฅผ ๋„์šด ์•กํ‹ฐ..

Dev_Study/Android 2018.01.26

1. ๋ ˆ์ด์•„์›ƒ ์ธํ”Œ๋ ˆ์ด์…˜

์ธํ”Œ๋ ˆ์ด์…˜(Inflation) ์•ˆ๋“œ๋กœ์ด๋“œ์—์„œ๋Š” ํ™”๋ฉด์„ ๊ตฌ์„ฑํ•˜๋Š” ๋ฐฉ๋ฒ•์œผ๋กœ XML๋ ˆ์ด์•„์›ƒ์„ ์‚ฌ์šฉํ•œ๋‹ค XML๋ ˆ์ด์•„์›ƒ ํŒŒ์ผ์˜ ๋‚ด์šฉ์€ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ์‹คํ–‰๋  ๋•Œ ๋ฉ”๋ชจ๋ฆฌ๋กœ ๋กœ๋”ฉ๋˜์–ด ๊ฐ์ฒดํ™”๋œ๋‹ค ์ด๋ ‡๊ฒŒ XML๋ ˆ์ด์•„์›ƒ์— ์ •์˜๋œ ๋‚ด์šฉ์ด ๋ฉ”๋กœ๋ฆฌ์ƒ์— ๊ฐ์ฒดํ™”๋˜๋Š” ๊ณผ์ •์„ ์ธํ”Œ๋ ˆ์ด์…˜์ด๋ผ๊ณ  ํ•œ๋‹ค ์ธํ”Œ๋ ˆ์ด์…˜ ๊ณผ์ • XML๋ ˆ์ด์•„์›ƒ ํŒŒ์ผ์€ ํ”„๋กœ์ ํŠธ๊ฐ€ ๋นŒ๋“œ๋˜๋Š” ์‹œ์ ์— ์ด์ง„ํŒŒ์ผ๋กœ ์ปดํŒŒ์ผ๋˜์ง€๋งŒ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ์‹คํ–‰์‹œ์ ์ด ๋˜์–ด์„œ์•ผ ๋กœ๋“œ๋˜์–ด ๋ฉ”๋ชจ๋ฆฌ์ƒ์— ๊ฐ์ฒดํ™”๊ฐ€ ๋œ๋‹ค setContentView()์˜ ์—ญํ•  [Reference] 1. ํ™”๋ฉด์— ๋‚˜ํƒ€๋‚ผ ๋ทฐ๋ฅผ ์ง€์ • 2. XML๋ ˆ์ด์•„์›ƒ์˜ ๋‚ด์šฉ์„ ๋ฉ”๋ชจ๋ฆฌ์ƒ์— ๊ฐ์ฒดํ™” setContentView()๋Š” ์•กํ‹ฐ๋น„ํ‹ฐ์˜ ํ™”๋ฉด์ „์ฒด๋ฅผ ์„ค์ •ํ•˜๋Š” ์—ญํ• ์„ ํ•˜๋ฏ€๋กœ ํ™”๋ฉด์ „์ฒด๊ฐ€ ์•„๋‹Œ ์ผ๋ถ€๋ทฐ๋งŒ์„ ์œ„ํ•œ XML๋ ˆ์ด์•„์›ƒ์„ ๋ฉ”๋ชจ๋ฆฌ์ƒ์— ๊ฐ์ฒดํ™”ํ•˜๋ ค๋ฉด ๋ณ„๋„์˜ ..

Dev_Study/Android 2018.01.25

[JAVA / SWING] ๋ฐฐ์น˜๊ด€๋ฆฌ์ž(Layout Manager) - CardLayout

import java.awt.BorderLayout; import java.awt.CardLayout; import java.awt.Color; import java.awt.Container; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class CardLayoutEx1 extends JFrame implements ActionListener{ JPanel jp; Cards cards; public CardLay..

[JAVA / SWING] ์„ฑ์ ๊ด€๋ฆฌ ํ”„๋กœ๊ทธ๋žจ v0.1

package com.std.cal; import java.awt.Color; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.math.BigDecimal; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; public class ScoreCal extends JFrame implements ActionListener{ JPanel jp1 = null; JLabel ..

[JAVA / SWING] ๋ฐฐ์น˜๊ด€๋ฆฌ์ž(Layout Manager) - BoxLayout

import java.awt.Component; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class BoxLayoutEx extends JFrame { public BoxLayoutEx (){ setTitle("BoxLayout ์ž…๋‹ˆ๋‹ค"); setSize(300, 300); setLocationRelativeTo(null); //ํ™”๋ฉด ์ค‘์•™์— ์ƒ์„ฑ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); JPanel jp = new JPanel(); jp.setLayout(ne..

[JAVA / SWING] ๋ฐฐ์น˜๊ด€๋ฆฌ์ž(Layout Manager) - GridLayout

import java.awt.GridLayout; import javax.swing.JButton; import javax.swing.JFrame; public class GridLayoutEx extends JFrame { public GridLayoutEx (){ setLayout(new GridLayout(0, 4)); //GridLayout(ํ–‰, ์—ด) setTitle("GridLayout ์ž…๋‹ˆ๋‹ค"); setSize(300, 300); setLocationRelativeTo(null); //ํ™”๋ฉด ์ค‘์•™์— ์ƒ์„ฑ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); JButton bt1 = new JButton("๋ฒ„ํŠผ1"); JButton ..