Search code examples
javaandroidandroid-activityhide

How to open application to run code without showing activity


I want when the user click on my application (when he open my application) the application run java without open the application or showing any activity.

Like Fast Task killer application.

And thanks.


Solution

  • Create transparent activity for this

    Here’s a complete file:

    res/values/styles.xml

    <resources>
      <style name="Theme.Transparent" parent="android:Theme">
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowIsFloating">true</item>
        <item name="android:backgroundDimEnabled">false</item>
      </style>
    </resources>
    

    Then apply the style to your activity, for example:

    <activity android:name=".SampleActivity" android:theme="@style/Theme.Transparent">
    ...
    </activity>