Android端æ«ã«å¯¾ãã¦ãä¸å®ä»¥ä¸ã®è² è·ãæãã㨠ActivityManager ãæ²é³´ãä¸ãã¦åActivity/Service ãè½ã¡ãå ´åãããã¾ãããã¡ããAppWidgetãä¾å¤ãªãè½ã¨ãããã®ã§ãããè½ã¨ãããã¢ããªãããä¸åº¦èµ·åããã㨠ActivityManager ã¯é å¼µã£ã¦ããã¾ãã
ãã¾ã ActivityManager ã追ã£ã¦ãªãã®ã§åããã¾ããããã©ãããè¨å®ã®ä»æ¹æ¬¡ç¬¬ã§ç¡äºåä½ãå§ããå ´åã¨ãåä½ããªãå ´åãããããã§ããä»åã¯ActivityManagerã«æ®ºããã¦ã復活ãã¦ãããããã³ã¼ããçµãã§ã¿ã¾ããã
è² è·ã®æãæ¹
Android端æ«ãã世界一重いページ!?ãµã¤ãã«ã¢ã¯ã»ã¹ãã¦LogCatãçºãã¦ä¸ããã
ActivityManager ã大éã®ãã°ãåãåºãã¦ãããééããªãã¢ãã¿ã®Android端æ«ã¯çæ»ã§ãã
ActivityManagerã®åãLog
ä¸å®ä»¥ä¸ã®è² è·ãæããéãActivityManager 㯠Low Memory: No more background processes. ã¨LogCatã«åãå§ãã¾ãã
ãã®éã«ã以ä¸ã®ããã«ããã»ã¹ã殺ããããçãè¿ã£ãããç¹°ãè¿ãã¾ããããã¦ããªãããã®çç±ã§äºåº¦ã¨Startãããªããªãã¾ã...
05-07 00:01:01.532: INFO/ActivityManager(74): Process jp.hyoromo.alarmmanagersample (pid 16268) has died. 05-07 00:01:08.282: INFO/ActivityManager(74): Start proc jp.hyoromo.alarmmanagersample for broadcast jp.hyoromo.alarmmanagersample/.AlarmManagerSample: pid=16327 uid=10071 gids={}
対ç
以ä¸ã®å¯¾çãè¬ããã¨è½ã¡ã¦ãå¿
ã復活ããããã«ãªãã¾ããã*1
- Alarmè¨å®æã«ä½¿ãContextãAppWidgetProviderã®ãã®ã«å¤æ´ã
- ãªã¼ãã©ã¤ãããonUpdateã¡ã½ããã使ãã®ã§ã¯ãªããonReceiveæã«ãã³ããªã³ã°ãã¦å¦çããããã«å¤æ´ã
ã½ã¼ã¹
@ITã§å ¬éããã¦ãããã¸ã¿ã«æè¨ã¦ã£ã¸ã§ãããæ¹è¯ãããµã³ãã«ã以ä¸ã®ããã«ãªãã¾ãã
public class AlarmManagerSample extends AppWidgetProvider { private static final long INTERVAL = 1000; @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action)) { setAlarm(context); Intent serviceIntent = new Intent(context, MyService.class); context.startService(serviceIntent); } super.onReceive(context, intent); } /** * PendingAlarmIntentãä½æ */ private PendingIntent getPendingAlarmIntent(Context context) { Intent intent = new Intent(context, AlarmManagerSample.class); intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0); return pendingIntent; } /** * ã¢ã©ã¼ã ãè¨å® */ private void setAlarm(Context context) { AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); long now = System.currentTimeMillis() + 1; long oneHourAfter = now + INTERVAL - now % (INTERVAL); alarmManager.set(AlarmManager.RTC_WAKEUP, oneHourAfter, getPendingAlarmIntent(context)); } /** * æè¨æ´æ°ãµã¼ãã¹å¦ç */ public static class MyService extends Service { @Override public void onStart(Intent intent, int startId) { Context context = getApplicationContext(); RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.alarm_manager_sample); remoteViews.setTextViewText(R.id.TextView01, new Date().toLocaleString()); ComponentName thisWidget = new ComponentName(context, AlarmManagerSample.class); AppWidgetManager manager = AppWidgetManager.getInstance(context); manager.updateAppWidget(thisWidget, remoteViews); } @Override public IBinder onBind(Intent intent) { return null; } } }
ã¾ããç§ããªãªã¼ã¹ãã¦ããVocaloidClockWidgetã§ãåæ§ã®å¯¾å¿ãè¡ã£ã¦ãã¾ããGitHubã§å ¬éãã¦ãã¾ãã®ã§ãåèã«ããã人ã¯ã©ããã
ä½è«
Task Killer ã§ããã»ã¹ã殺ãããå ´åã¯ã©ãããããããã¾ããã
ãªãã§ããã»ã¹ãæ»ãã§ãã¾ã復活ãããã¨è¨ã㨠ActivityManager 管çä¸ã®å
ãActivityManagerã«æ®ºãããããã§ããä»ã®ã¢ããªãã殺ãããå ´åã¯ActivityManagerã®ç¥ãã¬æãªã®ã§ããã»ã¹ãã¹ã¿ã¼ãããã¦ããã¾ããã
åèURLã¨ã人ã¨ã
AndroidのAppWidgetでupdatePeriodMillisを使わずに回す - だらだらとだらだら
AndroidのappWidget作成時に行っておくべき消費電力対策についてのまとめ(その1) - 闘争より逃走したい日記
adakodaさん
è²ã
åèã«ãªãã¾ããããããã¨ããããã¾ãã
*1:å¾è ã¯ãã¾ãé¢ä¿ãªããã