How to launch an Activity without a UI?

后端 未结 11 1640
失恋的感觉
失恋的感觉 2020-11-30 17:48

Is it in any way possible to launch an activity from the main function without having a UI? i.e. is there a way to create a sort of \"wrapper\" around another activity, i.e.

相关标签:
11条回答
  • 2020-11-30 18:22

    In your manifest, when you declare the activity, use theme "@android:style/Theme.Translucent.NoTitleBar"

    Ex:

    <activity android:name="yourActivityName" android:label="@string/app_name" android:theme="@android:style/Theme.Translucent.NoTitleBar">
    
    0 讨论(0)
  • 2020-11-30 18:25

    I think this would help you a lot:

    <activity  android:name = "MyActivity" 
              android:label = "@string/app_name" 
              android:theme = "@android:style/Theme.NoDisplay" >
    
    0 讨论(0)
  • If you are not interacting with the UI, what you are trying to do sounds more like an android service.

    0 讨论(0)
  • 2020-11-30 18:32

    I had used moveTaskToBack(true) in onResume() to put the entire activity stack in background.

    0 讨论(0)
  • 2020-11-30 18:35

    You need to add the Intent flag,

    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    

    Or

    call "finish();" after firing the intent.

    0 讨论(0)
  • 2020-11-30 18:35

    Just in case you are using Android 6.0+ or Target SDK is 23+, having a theme android:theme = "@android:style/Theme.NoDisplay" will lead to a crash with error did not call finish() prior to onResume() completing. This in fact is a bug recognised by Google developers here.

    So it is recommended to use an activity with following theme as a workaround.

    android:theme = "@android:style/Theme.Translucent.NoTitleBar"

    0 讨论(0)
提交回复
热议问题