Autore Topic: Crash di un service  (Letto 819 volte)

Offline terenz84

  • Nuovo arrivato
  • *
  • Post: 31
  • Respect: 0
    • Mostra profilo
Crash di un service
« il: 12 Gennaio 2011, 13:20:41 CET »
0
Sto creando un service che ogni tot di tempo lavora in backgroud.

Il problema è che funzione per 2-3 cicli ma poi viene stoppato

Codice (Java): [Seleziona]
01-12 11:34:12.241: INFO/ServiceAutoStarter(262): onReceive
01-12 11:34:12.281: INFO/SyncService(262): SyncService started
01-12 11:34:12.481: INFO/SyncService(262): SyncService DataBase started
01-12 11:34:12.501: INFO/SyncService(262): SCHEDULER
01-12 11:34:12.511: INFO/SyncService(262): SyncService onStartPicasa Neolution
01-12 11:34:12.511: INFO/SyncService(262): SyncService onStartFTP Neolution
01-12 11:34:12.531: INFO/SyncService(262): SyncService onStartTest Account
01-12 11:34:12.531: INFO/SyncService(262): Start TAsk Test Account
01-12 11:34:12.881: INFO//system/bin/fsck_msdos(29): Attempting to allocate 794 KB for FAT
01-12 11:34:13.151: DEBUG/PackageParser(59): Scanning package: /data/app/vmdl22264.tmp
01-12 11:34:13.291: WARN/PackageParser(59): Unknown element under <application>: uses-sdk at /data/app/vmdl22264.tmp Binary XML file line #18
01-12 11:34:13.321: INFO/PackageParser(59): com.PhotoBackup: compat added android.permission.WRITE_EXTERNAL_STORAGE android.permission.READ_PHONE_STATE
01-12 11:34:13.481: INFO//system/bin/fsck_msdos(29): ** Phase 2 - Check Cluster Chains
01-12 11:34:13.511: INFO//system/bin/fsck_msdos(29): ** Phase 3 - Checking Directories
01-12 11:34:13.511: INFO//system/bin/fsck_msdos(29): ** Phase 4 - Checking for Lost Files
01-12 11:34:13.521: INFO//system/bin/fsck_msdos(29): 20 files, 95561 free (191123 clusters)
01-12 11:34:13.551: INFO/logwrapper(29): /system/bin/fsck_msdos terminated by exit(0)
01-12 11:34:13.551: INFO/Vold(29): Filesystem check completed OK
01-12 11:34:13.551: INFO/Vold(29): Device /dev/block/vold/179:0, target /mnt/sdcard mounted @ /mnt/secure/staging
01-12 11:34:13.561: DEBUG/Vold(29): Volume sdcard state changing 3 (Checking) -> 4 (Mounted)
01-12 11:34:13.561: INFO/PackageManager(59): Updating external media status from unmounted to mounted
01-12 11:34:13.571: INFO/StorageNotification(59): Media {/mnt/sdcard} state changed from {checking} -> {mounted}
01-12 11:34:13.691: DEBUG/MediaScanner(223):  prescan time: 3625ms
01-12 11:34:13.691: DEBUG/MediaScanner(223):     scan time: 123ms
01-12 11:34:13.691: DEBUG/MediaScanner(223): postscan time: 221ms
01-12 11:34:13.691: DEBUG/MediaScanner(223):    total time: 3969ms
01-12 11:34:13.721: DEBUG/MediaScannerService(223): done scanning volume internal
01-12 11:34:14.281: INFO/Launcher.Model(125): not binding apps: no Launcher activity
01-12 11:34:14.411: DEBUG/dalvikvm(125): GC_EXPLICIT freed 4006 objects / 225304 bytes in 123ms
01-12 11:34:14.561: INFO/PackageManager(59): Removing non-system package:com.PhotoBackup
01-12 11:34:15.041: DEBUG/PackageManager(59): Scanning package com.PhotoBackup
01-12 11:34:15.041: INFO/PackageManager(59): Package com.PhotoBackup codePath changed from /data/app/com.PhotoBackup-2.apk to /data/app/com.PhotoBackup-1.apk; Retaining data and using new
01-12 11:34:15.201: INFO/PackageManager(59): /data/app/com.PhotoBackup-1.apk changed; unpacking
01-12 11:34:15.461: DEBUG/installd(35): DexInv: --- BEGIN '/data/app/com.PhotoBackup-1.apk' ---
01-12 11:34:15.561: DEBUG/dalvikvm(125): GC_EXPLICIT freed 10916 objects / 531536 bytes in 118ms
01-12 11:34:17.201: DEBUG/dalvikvm(273): DexOpt: load 411ms, verify 743ms, opt 21ms
01-12 11:34:17.222: DEBUG/installd(35): DexInv: --- END '/data/app/com.PhotoBackup-1.apk' (success) ---
01-12 11:34:17.232: WARN/PackageManager(59): Code path for pkg : com.PhotoBackup changing from /data/app/com.PhotoBackup-2.apk to /data/app/com.PhotoBackup-1.apk
01-12 11:34:17.232: WARN/PackageManager(59): Resource path for pkg : com.PhotoBackup changing from /data/app/com.PhotoBackup-2.apk to /data/app/com.PhotoBackup-1.apk
01-12 11:34:17.232: DEBUG/PackageManager(59):   Services: com.PhotoBackup.SyncService
01-12 11:34:17.232: DEBUG/PackageManager(59):   Receivers: com.PhotoBackup.ServiceAutoStarter
01-12 11:34:17.232: DEBUG/PackageManager(59):   Activities: com.PhotoBackup.AccountList com.PhotoBackup.AccountType com.PhotoBackup.AccountPicasa com.PhotoBackup.AccountFtp com.PhotoBackup.PictureList com.PhotoBackup.PictureDetail
01-12 11:34:17.472: DEBUG/dalvikvm(59): GC_FOR_MALLOC freed 8973 objects / 485280 bytes in 109ms
01-12 11:34:17.472: INFO/installd(35): move /data/dalvik-cache/data@app@com.PhotoBackup-1.apk@classes.dex -> /data/dalvik-cache/data@app@com.PhotoBackup-1.apk@classes.dex
01-12 11:34:17.472: DEBUG/PackageManager(59): New package installed in /data/app/com.PhotoBackup-1.apk
01-12 11:34:17.562: INFO/SyncService(262): SCHEDULER
01-12 11:34:17.682: DEBUG/VoldCmdListener(29): asec list
01-12 11:34:17.682: INFO/PackageManager(59): No secure containers on sdcard
01-12 11:34:17.692: WARN/PackageManager(59): Unknown permission com.google.android.gm.permission.WRITE_GMAIL in package com.android.settings
01-12 11:34:17.692: WARN/PackageManager(59): Unknown permission com.google.android.gm.permission.READ_GMAIL in package com.android.settings
01-12 11:34:17.692: WARN/PackageManager(59): Unknown permission com.google.android.googleapps.permission.GOOGLE_AUTH in package com.android.settings
01-12 11:34:17.692: WARN/PackageManager(59): Unknown permission com.google.android.googleapps.permission.GOOGLE_AUTH in package com.android.providers.contacts
01-12 11:34:17.692: WARN/PackageManager(59): Unknown permission com.google.android.googleapps.permission.GOOGLE_AUTH.cp in package com.android.providers.contacts
01-12 11:34:17.692: WARN/PackageManager(59): Unknown permission com.google.android.googleapps.permission.GOOGLE_AUTH.mail in package com.android.contacts
01-12 11:34:17.692: WARN/PackageManager(59): Unknown permission android.permission.ADD_SYSTEM_SERVICE in package com.android.phone
01-12 11:34:17.702: WARN/PackageManager(59): Unknown permission com.google.android.googleapps.permission.ACCESS_GOOGLE_PASSWORD in package com.android.development
01-12 11:34:17.702: WARN/PackageManager(59): Unknown permission com.google.android.googleapps.permission.GOOGLE_AUTH in package com.android.development
01-12 11:34:17.702: WARN/PackageManager(59): Unknown permission com.google.android.googleapps.permission.GOOGLE_AUTH.ALL_SERVICES in package com.android.development
01-12 11:34:17.702: WARN/PackageManager(59): Unknown permission com.google.android.googleapps.permission.GOOGLE_AUTH.YouTubeUser in package com.android.development
01-12 11:34:17.702: WARN/PackageManager(59): Not granting permission android.permission.SEND_DOWNLOAD_COMPLETED_INTENTS to package com.android.browser (protectionLevel=2 flags=0x1be45)
01-12 11:34:17.982: INFO/ActivityManager(59): Force stopping package com.PhotoBackup uid=10033
01-12 11:34:17.982: WARN/ActivityManager(59): Scheduling restart of crashed service com.PhotoBackup/.SyncService in 5000ms
01-12 11:34:17.982: INFO/Process(59): Sending signal. PID: 262 SIG: 9
01-12 11:34:18.002: INFO/ActivityManager(59):   Force stopping service ServiceRecord{43f67588 com.PhotoBackup/.SyncService}
01-12 11:34:18.002: INFO/ActivityManager(59): Force stopping package com.PhotoBackup uid=10033
01-12 11:34:18.102: INFO/ActivityManager(59): Force stopping package com.PhotoBackup uid=10033

ecco il mio service:

Codice (Java): [Seleziona]
package com.PhotoBackup;

import java.io.IOException;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

import com.PhotoBackup.MyObject.Account;

import android.app.Service;
import android.content.Intent;
import android.database.SQLException;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.IBinder;
import android.util.Log;


public class SyncService extends Service {
       
        static final String TAG = "SyncService";
        private DataBaseHelper myDbHelper;
       
        private Timer mTimer;
        private final long mPeriod = 5000;
        private final long mDelay = 0;



        @Override
        public void onCreate() {  
                super.onCreate();
                Log.i(TAG,"SyncService started");
                initDataBase();
                Log.i(TAG,"SyncService DataBase started");
                mTimer = new Timer();
                mTask = new Task();
        }  
       
        @Override
    public void onStart(Intent intent, int startId) {
        super.onStart(intent, startId);
        mTimer.schedule(mTask, mDelay, mPeriod);
        List<Account> accounts = myDbHelper.getAllAccount();
                if(accounts.size() > 0){
                        for(int i = 0; i < accounts.size();i++){
                                Log.i(TAG,"SyncService onStart" + accounts.get(i).AccountName);
                                if(startTask(accounts.get(i))){
                                        Log.i(TAG,"Start TAsk " + accounts.get(i).AccountName);
                                }                              
                        }
                }
        }
       
        private class Task extends TimerTask{
                public void run(){
                        Log.i(TAG, "SCHEDULER");
                }
        }
       
        private Task mTask;

       
        @Override
        public IBinder onBind(Intent intent) {
                return null;
        }
       
   /* This method initialize the database
    * If is the First run, the database is created and opened.
    * Otherwise open only the DataBase
    */

   public void initDataBase(){
        myDbHelper = new DataBaseHelper(this);

       try {
        myDbHelper.createDataBase();
       } catch (IOException ioe) {
        throw new Error("Unable to create database");
                }
       
                try {
                        myDbHelper.openDataBase();
                        MyApplication appState = ((MyApplication)getApplicationContext());
                appState.setMyDbHelper(myDbHelper);
                }catch(SQLException sqle){
                        throw sqle;
                }
   }
   
   public Boolean startTask(Account account){
           switch((int)account.SchedulerActive){
                        case 0://No Scheduler
                                return false;
                        case 1://Scheduler only if WIFI
                                ConnectivityManager connManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
                                NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
                                if (mWifi.isConnected()) {
                                   // Do whatever
                                        return true;
                                }
                                break;
                        case 2://Scheduler always
                                return true;               
           }
           
           return false;
   }
   
}

Qualche idea?