[Android] Intent

[Android] Intent

์ธํ…ํŠธ

: Application ์ปดํฌ๋„ŒํŠธ ๊ฐ„์— ์ž‘์—… ์ˆ˜ํ–‰์„ ์œ„ํ•œ ์ •๋ณด๋ฅผ ์ „๋‹ฌํ•˜๋Š” ์—ญํ• 

  • startActivity(): ์•กํ‹ฐ๋น„ํ‹ฐ๋ฅผ ํ™”๋ฉด์— ๋„์šธ ๋•Œ
  • startService(): ์„œ๋น„์Šค๋ฅผ ์‹œ์ž‘ํ•  ๋•Œ
  • broadcastIntent(): ๋ธŒ๋กœ๋“œ์บ์ŠคํŒ…์„ ์ˆ˜ํ–‰ํ•  ๋•Œ

์ธํ…ํŠธ์˜ ๊ธฐ๋ณธ ๊ตฌ์„ฑ ์š”์†Œ

  • ์•ก์…˜
    ์ˆ˜ํ–‰ํ•  ๊ธฐ๋Šฅ
    • ์˜ˆ) ACTION_VIEW, ACTION_EDIT โ€ฆ
  • ๋ฐ์ดํ„ฐ
    ์•ก์…˜์ด ์ˆ˜ํ–‰๋  ๋Œ€์ƒ ๋ฐ์ดํ„ฐ
  • Extra Data
    ์ถ”๊ฐ€์ ์ธ ์ •๋ณด๋ฅผ ๋„ฃ์„ ์ˆ˜ ์žˆ๋Š” Bundle ๊ฐ์ฒด


ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย Intent(Action + Data)
์•กํ‹ฐ๋น„ํ‹ฐA โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”> ์•กํ‹ฐ๋น„ํ‹ฐB

๋ช…์‹œ์  ์ธํ…ํŠธ / ์•”์‹œ์  ์ธํ…ํŠธ

๋ช…์‹œ์  ์ธํ…ํŠธ

: ์ธํ…ํŠธ์— ํด๋ž˜์Šค ๊ฐ์ฒด๋‚˜ ์ปดํฌ๋„ŒํŠธ ์ด๋ฆ„์„ ์ง€์ •ํ•˜์—ฌ ํ˜ธ์ถœํ•  ๋Œ€์ƒ์„ ํ™•์‹คํžˆ ์•Œ ์ˆ˜ ์žˆ๋Š” ๊ฒฝ์šฐ


MainActivity.java

public void mOnClick(View v) {
    switch (v.getId()) {
        case R.id.btnedit:
            Intent intent = new Intent(this, ActEdit.class);
            intent.putExtra("TextIn", mText.getText().toString());
            startActivityForResult(intent, ACT_EDIT);
            break;
    }
}
์•”์‹œ์  ์ธํ…ํŠธ

: ์•ก์…˜๊ณผ ๋ฐ์ดํ„ฐ๋ฅผ ์ง€์ •ํ•˜๊ธด ํ–ˆ์ง€๋งŒ ํ˜ธ์ถœํ•  ๋Œ€์ƒ์ด ๋‹ฌ๋ผ์งˆ ์ˆ˜ ์žˆ๋Š” ๊ฒฝ์šฐ
์•ˆ๋“œ๋กœ์ด๋“œ ์‹œ์Šคํ…œ์ด ์ธํ…ํŠธ๋ฅผ ์ด์šฉํ•ด ์š”์ฒญํ•œ ์ •๋ณด๋ฅผ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋Š” ์ ์ ˆํ•œ ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ฐพ์•„๋ณธ ๋‹ค์Œ,
์‚ฌ์šฉ์ž์—๊ฒŒ ๊ทธ ๋Œ€์ƒ๊ณผ ์ฒ˜๋ฆฌ ๊ฒฐ๊ณผ๋ฅผ ๋ณด์—ฌ์ฃผ๋Š” ๊ณผ์ •

  • Category: ์•ก์…˜ ์‹คํ–‰์— ํ•„์š”ํ•œ ์ถ”๊ฐ€์ ์ธ ์ •๋ณด
  • Type: ์ธํ…ํŠธ์— ๋“ค์–ด๊ฐ€๋Š” ๋ฐ์ดํ„ฐ์˜ MIME ํƒ€์ž…
  • Component: ์ธํ…ํŠธ์— ์‚ฌ์šฉ๋  ์ปดํฌ๋„ŒํŠธ ํด๋ž˜์Šค ์ด๋ฆ„

MainActivity.java

public void mOnClick(View v) {
    switch (v.getId()) {
        case R.id.btnedit:
            Intent intent = new Intent(Intent.ACTION_EDIT);
            intent.putExtra("TextIn", mText.getText().toString());
            startActivityForResult(intent, ACT_EDIT);
            break;
    }
}

AndroidManifest.xml

<activity android:name=".ActEdit" android:label="Edit">
    <intent-filter>
        <action android:name="android.intent.action.EDIT"/>
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

์ธํ…ํŠธ ํ•„ํ„ฐ

์‹œ์Šคํ…œ์ด ์š”์ฒญํ•˜๋Š” ์ธํ…ํŠธ์˜ ์ •๋ณด๋ฅผ ๋ฐ›์•„ ์ฒ˜๋ฆฌํ•  ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ตฌ์„ฑ ์š”์†Œ๋ฅผ ์ฐพ๊ธฐ ์œ„ํ•ด ํ•„์š”ํ•œ ์ •๋ณด
์ธํ…ํŠธ ํ•„ํ„ฐ์˜ ์•ก์…˜ ์ •๋ณด = ์ธํ…ํŠธ ํ•„ํ„ฐ์— ์ง€์ •ํ•œ ์ธํ…ํŠธ๋งŒ ์ „๋‹ฌ๋ฐ›๊ฒ ๋‹ค๋Š” ์˜๋ฏธ


[์ฐธ๊ณ ]
์•ˆ๋“œ๋กœ์ด๋“œ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์ •๋ณต 1,2๊ถŒ
Do it! ์•ˆ๋“œ๋กœ์ด๋“œ ์•ฑ ํ”„๋กœ๊ทธ๋ž˜๋ฐ
Android Developers

Comments