是否可以创建一个将在 android 模拟器中运行的纯控制台 android 应用程序?
我的意思是我们可以运行利用 System.out.println
的经典桌面 Java 应用程序。对于控制台输出,所以我不明白为什么我们不能通过 android.util.Log
为 Android 做同样的事情类。
在模拟器上执行此操作的优点是可以访问由 Android Java 类实现的所需功能。
可能是没有 Application
的 dex 文件, Activity
类和 AndroidManifest.xml
如何最好地做到这一点?
最佳答案
没有“AndroidMain”方法。
您可以使用没有 UI 的主 Activity 或启动服务来完成此操作。
例如。
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();
}
}
我的服务.java
public class MyService extends IntentService {
public MyService() {
super("MyService");
}
@Override
protected void onHandleIntent(Intent intent) {
Log.i("MyService", "Hello world!");
}
}
关于java - 纯控制台Android应用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39819703/