ȸ¿ø°¡ÀԡžÆÀ̵ð/ºñ¹øã±â
ȨÀ¸·Î

Service & Notification(¾Ë¸²¹Ù¶ç¿ì±â) ÀÌ¿ëÇϱâ
7³â Àü
Service
¼­ºñ½º´Â ¹é±×¶ó¿îµå¿¡¼­ ÀÛµ¿Çϸç Content Provider ¸¦ ¾÷µ¥ÀÌÆ®Çϰųª ÀÎÅÙÆ®¸¦ ½ÇÇà½ÃÅ°°Å³ª Notification(¾Ë¸²)À»
½ÇÇà½ÃÅ°´Â µîÀÇ ¿©·¯°¡Áö ÀÛ¾÷À» ÀÚµ¿À¸·Î ¼öÇàÇÏ´Â ÀÛ¾÷À» ¶æÇÑ´Ù. ÇÏÁö¸¸ ±âº»ÀûÀ¸·Î ANRÀ» ¸·±â À§Çؼ­ µ¹¾Æ°¡´Â
¾²·¹µåÀÇ °³³äÀÌ ¾Æ´Ï¶ó °°Àº ÇÁ·Î¼¼½º ¾È¿¡¼­ ½ÇÇàµÇ´Â °³³äÀÌ´Ù.

(1) ÀÛ¼º°ú ½ÇÇà
  Service Ŭ·¡½º¸¦ »ó¼Ó¹Þ°í, onCreate(¼­ºñ½º°¡ ¸¸µé¾îÁ³À» °æ¿ì ½ÇÇàµÉ ·ÎÁ÷ ÀÛ¼º),
  onBind(AIDL ÀÌ¿ë½Ã ÇÊ¿ä) ¸Þ¼Òµå¸¦ ¿À¹ö¶óÀ̵ùÇÑ´Ù.

  <1> onStartCommand ÀÇ ¿À¹ö¶óÀ̵ù°ú return
   ºÎ°¡ÀûÀ¸·Î ´ëºÎºÐ onStartCommand ¸Þ¼ÒµåÀÇ ¿À¹ö¶óÀ̵ùÀÌ ÇÊ¿äÇѵ¥ ÀÌ ¸Þ¼Òµå¸¦ ÅëÇؼ­ startService ¸Þ¼Òµå
   È£Ãâ½ÃÀÇ ÀÛµ¿ ¹æ½ÄÀ» Á¤ÀÇÇÒ ¼ö ÀÖ´Ù.(2.0 ÀÌÀüÀº onStart()¿¡ ±¸ÇöÇß¾ú´Ù.)
   - START_STICKY : ÀϹÝÀûÀÎ °æ¿ì ÀÌ °ªÀ» ¸®ÅÏÇÏ°Ô µÇ°í, ½ÇÇ൵Áß ¼­ºñ½º°¡ Á¾·áµÆ´Ù°¡ ´Ù½Ã ½ÃÀÛ½Ã
    onStartCommand ¸Þ¼Òµå°¡ °è¼Ó ½ÇÇàµÇ°Ô µÈ´Ù.
   - START_NOT_STICKY
   - START_REDELIVER_INTENT

  <2> AndroidManifest.xml ¿¡ ¼³Á¤
            <service android:name="AIDLService">
                <intent-filter>
                    <action android:name="com.kh.service.AIDL" />
                </intent-filter>
            </service>

  <3> ÇØ´ç¼­ºñ½º¸¦ ½ÇÇà½ÃÅ°°í ½ÍÀ»¶§ startService(intent)¸¦ ÅëÇؼ­ ½ÇÇàÇÏ´Â °ÍÀÌ °¡´ÉÇÏ´Ù.
         À̶§ ¿ÜºÎ ÇÁ·Î±×·¥¿¡¼­µµ ½ÇÇàÀÌ °¡´ÉÇѵ¥ À̶§´Â intent¿¡ ActionÀ» intent-filter¿¡ ÁöÁ¤Çß´ø actionÀ¸·Î
         ÁöÁ¤ÇÔÀ¸·Î¼­ ¿ÜºÎ¿¡¼­µµ ¼­ºñ½º¸¦ È£ÃâÇÏ´Â °ÍÀÌ °¡´ÉÇÏ°Ô µÈ´Ù.


Âü°í »çÀÌÆ®
http://developer.android.com/guide/topics/ui/notifiers/notifications.html - ¾Ë¸²¹Ù ¶ç¿ì±â

»ç¿ë ¿¹Á¦
package com.example.serviceapp;

import android.app.*;
import android.content.*;
import android.os.*;
import android.support.v4.app.*;
import android.support.v4.app.NotificationCompat.*;
import android.util.*;
import android.widget.*;

public class TimeService extends Service {

      @Override
      public IBinder onBind(Intent intent) {
            return null;
      }
    
      @Override
      public void onCreate() {
            Log.d("service","onCreate ½ÇÇà");
      }

      @Override
      public void onDestroy() {
            Log.d("service","onDestroy ½ÇÇà");
            mRunning = false;
      }
    
    
      private Handler mHandler = new Handler() {
            public void handleMessage(Message msg) {
//               switch(msg.what) {}
//               Toast.makeText(getApplicationContext(), "¾Ë¸²!", 0).show();
                  NotificationManager manager =
                             (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
                
                  NotificationCompat.Builder builder =
                            new NotificationCompat.Builder(TimeService.this);
                  builder.setSmallIcon(R.drawable.ic_launcher)
                             .setContentTitle("¾Ë¸³´Ï´Ù")
                             .setContentText("¿Ô´Ù³×~¿Ô´Ù³×~ ³»~°¡ ¿Ô´Ù³×~")
                             .setAutoCancel(true) // ¾Ë¸²¹Ù¿¡¼­ ÀÚµ¿ »èÁ¦
                             .setVibrate(new long[]{1000,2000,1000,3000,1000,4000});
                             // autoCancel : Çѹø ´©¸£¸é ¾Ë¸²¹Ù¿¡¼­ »ç¶óÁø´Ù.
                             // vibrate : ½¬°í, ¿ï¸®°í, ½¬°í, ¿ï¸®°í... ¹Ð¸®¼¼ÄÁ
                             // Áøµ¿ÀÌ µÇ·Á¸é AndroidManifest.xml¿¡ Áøµ¿ ±ÇÇÑÀ» Áà¾ß ÇÑ´Ù.
                
                  // ¾Ë¶÷ Ŭ¸¯½Ã MainActivity¸¦ È­¸é¿¡ ¶ç¿î´Ù.
                  Intent intent = new Intent(getApplicationContext(),MainActivity.class);
                  PendingIntent pIntent = PendingIntent.getActivity(getApplicationContext()
                             , 0
                             , intent
                             , Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
                  builder.setContentIntent(pIntent);
                  manager.notify(1, builder.build());
            };
      };
      protected boolean mRunning;
    
    
      // Á¦ÀÏ Áß¿äÇÑ ¸Þ¼­µå! (¼­ºñ½º ÀÛµ¿³»¿ëÀ» ³Ö¾îÁØ´Ù.)
      @Override
      public int onStartCommand(Intent intent, int flags, int startId) {
            Log.d("service","onStartCommand ½ÇÇà");
            final int time = intent.getIntExtra("time", 0);
//          Toast.makeText(this, "¾È³ç~ ³­ ¼­ºñ½º : "+time, 0).show();
          
            // handler ÅëÇÑ Thread ÀÌ¿ë
            new Thread(new Runnable() {

                  @Override
                  public void run() {
                        mRunning = true;
                        while(mRunning) {
                             SystemClock.sleep(time*1000);
                             mHandler.sendEmptyMessage(0);
                        }
                  }
                
            }).start();
          
          
            return START_STICKY_COMPATIBILITY;
      }
}
ÃßõÃßõ : 217 Ãßõ ¸ñ·Ï
¹øÈ£ Á¦¸ñ
1,226
android | ²¨Áø È­¸é¿¡¼­ ¾Û ½ÇÇàÇϱâ / Àáµç È­¸é ±ú¿ì±â / Àá±Ý È­¸é À§·Î ½ÇÇà/
1,225
android ÇöÀç WebView¿¡¼­ ¿ÜºÎ ÆäÀÌÁö ºÒ·¯¿À±â / WebView »õâ ¶ç¿ìÁö ¾Ê±â / WebViewClient
1,224
Activity ¸¦ dialog style·Î ¸¸µé±â
1,223
webview ¾Æ·¡ button ³Ö±â
1,222
webview scroll ±â´É ¸·±â(touch´Â µÊ)
1,221
Service µî·ÏÇϱâ
1,220
booting ÈÄ¿¡ ÀÚµ¿À¸·Î ½ÇÇà µÇ´Â app ¸¸µé±â
1,219
[Android] Intent È°¿ë ¿¹½Ã
1,218
Android ¼³Ä¡µÈ ¾îÇà ¸ñ·Ï PackageInfo¸¦ ÅëÇØ °¡Á®¿À±â ¹× ´Ù¸¥ ¾îÇà ½ÇÇà
1,217
[ANDROID(¾Èµå·ÎÀ̵å) ¾Û °³¹ß ±âÃÊ] MEDIAPLAYER À½¾Ç Àç»ýÇϱâ
1,216
[¾Èµå·ÎÀ̵å] ¿ÜºÎ ¾Û ½ÇÇà
1,215
¾Èµå·ÎÀÌµå ¼º´ÉÀ» À§ÇÑ ¼³°è
1,214
ÆÄÀÏ ¾÷·Îµå ¹× ÆĶó¸ÞÅÍ Àü¼Û (sending file & parameters by MultipartEntity / post)
1,213
MediaPlayer °¡·ÎÀÏ ¶§ UI ¼û±â°í Ç®½ºÅ©¸° ¸¸µé±â
1,212
À¥ºä¿¡¼­ html ÅÂ±× ¾ø¾Ö´Â ¹ý(Remove the html tag on loading web page in WebView)
1,211
´Ù¸¥ ¾Û ½ÇÇàÇϰųª Ç÷¹ÀÌ ½ºÅä¾î·Î À̵¿(Launch another app by code)
1,210
À¥ ºä¿¡¼­ ÅÂ±× Á¤º¸ ÃàÃâÇϱâ(Get the information of html tag in WebView of android)
1,209
ÀÚµ¿À¸·Î ¿¡µðÆ®ºä¿¡ Æ÷Ä¿½º µÇ´Â °Í ¸·±â
1,208
addJavascriptInterface ¿À·ù(Android WebView.addJavascriptInterface not Working)
1,207
Ä¿½ºÅÒ Å佺Ʈ ¶ç¿ì±â(To show Custom Toast)
1,206
À¥¿¡¼­ ÆÄÀÏ »çÀÌÁî¿Í ÄÜÅÙÆ®(ÄÁÅÙÃ÷) ŸÀÔ ¾Ë¾Æº¸´Â »ùÇÃÄÚµå
1,205
¾Èµå·ÎÀ̵å ÅؽºÆ® ºä¿¡¼­ Áö¿øÇÏ´Â HTML ű׵é
1,204
ÀÎÅÍ³Ý ÁÖ¼Ò À¯È¿¼º °Ë»ç (regular expression for url)
1,203
SpannableStringÀ¸·Î ÅؽºÆ® ºä¿¡ ¾ÆÀÌÄÜ ³Ö´Â ¹ý
1,202
½ÇÇà°¡´ÉÇÑ ¾Û ¸ñ·Ï (Get launchable apps in android)
1,201
HTMLÀ» ¾Èµå·ÎÀ̵å À¥ºä¿¡ ¸ðµÎ º¸ÀÌ°Ô Çϱâ Using WebView ViewPort in android
1,200
so ÆÄÀÏ ¾Èµå·ÎÀÌµå ½ºÆ©µð¿À¿¡¼­ »ç¿ëÇÏ´Â ¹ý
1,199
[¾Èµå·ÎÀ̵å] È­¸é »çÀÌÁî ±¸Çϱâ
1,198
[¾Èµå·ÎÀ̵å] ¾Èµå·ÎÀÌµå ½ºÆ©µð¿À¿¡¼­ ºôµå ÆÄÀÏ À̸§ ¼öÁ¤Çϱâ.
1,197
¿ÜºÎ ¾Û ½ÇÇà½ÃÅ°±â (launch external app in android)
¸ñ·Ï
¹ÂÁ÷Æ®·ÎÆ® ºÎ»ê±¤¿ª½Ã ºÎ»êÁø±¸ °¡¾ßµ¿ ¤Ó °³ÀÎÁ¤º¸Ãë±Þ¹æħ
Copyright ¨Ï musictrot All rights reserved.