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

<application
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name">

    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <service android:name=".MyService" />
</application>

MainActivity.java

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Intent i = new Intent(this, MyService.class);
        startService(i);
        finish();
    }
}

MyService.java

public class MyService extends IntentService {

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

    @Override
    protected void onHandleIntent(Intent intent) {
        Log.i("MyService", "Hello world!");
    }
}

Post a Comment for "Pure Console Android Application?"