Skip to content Skip to sidebar Skip to footer

Pure Console Android Application?

Is it possible to create a pure console android application that will run in the android emulator? I mean we can run classic desktop Java application that utilize System.out.printl

Solution 1:

There is no "AndroidMain" method. You can accomplish this using a main Activity without UI or launching a Service.

E.g.

AndroidManifest.xml

<applicationandroid:icon="@mipmap/ic_launcher"android:label="@string/app_name"><activityandroid:name=".MainActivity"><intent-filter><actionandroid:name="android.intent.action.MAIN" /><categoryandroid:name="android.intent.category.LAUNCHER" /></intent-filter></activity><serviceandroid:name=".MyService" /></application>

MainActivity.java

publicclassMainActivityextendsAppCompatActivity {

    @OverrideprotectedvoidonCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Intenti=newIntent(this, MyService.class);
        startService(i);
        finish();
    }
}

MyService.java

publicclassMyServiceextendsIntentService {

    publicMyService() {
        super("MyService");
    }

    @OverrideprotectedvoidonHandleIntent(Intent intent) {
        Log.i("MyService", "Hello world!");
    }
}

Post a Comment for "Pure Console Android Application?"