Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Service doesn't show Logs

Question


I got a little problem to see what happens in my Service. I don't get any logs of it. So first I thought I probably don't start my Service, but this isn't the problem. When I go to Running-Apps on my Device the Service is listed up there.

Now lets take a look at the Code:

Manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="de.ivocore"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="14" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" 
        android:theme="@style/Theme.IVOCore"
        android:debuggable="true">

        <service android:name=".service.DataHandlerService" />
          <!--    android:enabled="true"
            android:icon="@drawable/ic_launcher"/>

        android:process=":DataHandler" -->

        <activity
            android:label="@string/app_name"
            android:name=".LoginActivity" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />
                <action android:name="de.ivocore.LOGINCHECK"/>
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity 
            android:name=".MainActivity"></activity>    

    </application>


        <!-- Definieren welche Permission's die Applikation besitzt -->
        <uses-permission android:name="android.permission.INTERNET" />

</manifest>

MainActivity.class

I start the Service here in my onCreate().

package de.ivocore;

import de.ivocore.service.DataHandlerService;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;

public class MainActivity extends Activity {

    private final String LOAD_ORDER = "de.ivocore.MainActivity.LOAD_ORDER";

    //Verschiedene Integer definieren für Switch/Case damit der Service weis was zu tun ist
    int FIRST_LOAD = 0; //Wird gesendet beim onCreate der Activity
    int RELOAD = 1; //Wird gesendet wenn der User einen reload möchte

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        //Service starten zusätlich wird folgender Parameter mitgegeben "onstart" 
        //dies zeigt dem Service das die Activity gerade gestartet wurde.
        Intent i = new Intent(this, DataHandlerService.class);
        i.putExtra(LOAD_ORDER, FIRST_LOAD);
        startService(i);
    }



    public void onReceive(Intent intent){

    }
}

DataHandlerService.class

Here i catch the Intent over onStartCommand(), which probably dosn't work. But I don't get whats wrong there...

public class DataHandlerService extends Service {
    private AlarmManager alarmManager;
    private Calendar calendar;
    private static final int PERIOD = 60000 * 60; // 1h
    private final String LOAD_VIDEO = "de.ivocore.service.DataHandlerService.LOAD_VIDEO";
    private final String LOAD_ORDER = "de.ivocore.MainActivity.LOAD_ORDER";

    LoginAdapter mDbHelper = new LoginAdapter(this);

    @Override
    public IBinder onBind(Intent intent) {
        // TODO Auto-generated method stub
        return null;
    }


    public void onStartCommand(Intent intent, int flags, String startID){
        int load = intent.getIntExtra(LOAD_ORDER, 0);
        Log.d("DataHandlerService",  "Activity startet mit folgendem Parameter ="+load);

        switch (load){
        case 0:
            Log.d("DataHandlerService", "Es wird def OfficeTimerOnStart gestartet");
            checkOfficeTimeOnStart();
        break;
        case 1:
            getOrders();
        break;
        }



    }

    public void onDestroy(){
        stopSelf();
    }
}

Please tell me what I'm doing wrong, that I can see my Logs!

Thank you in Advance.

Best Regards

safari

like image 461
safari Avatar asked Jan 19 '12 12:01

safari


1 Answers

This is quite old post, but I ended here anyway, when I had the same problem in Android Studio. For those who will end up here just like me, following might be the problem:

enter image description here

like image 200
Divole Avatar answered Nov 15 '22 06:11

Divole