4

StackOverfow 上有很多类似的问题,但它们并没有解决我的问题。

任务是处理来自不同应用程序的使用默认共享机制(ACTION_SEND)发送的服务意图。
但就ACTION_SEND活动而言,我们必须在活动中获取意图并将其广播到服务中。如果此活动对用户不可见,那将是完美的。

我已经研究了很多,并且已经尝试了很多解决方案。

  1. 使活动隐形的第一步属于活动风格。

    我已经尝试过这个值。

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

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

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

    我也尝试过创建自定义主题。

    <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:backgroundDimEnabled">true</item>
    </style>
    

    AndroidManifest.xml 中的活动的样子。

    <activity
        android:name="xxx.xxx.activities.HandleShareIntentActivity"
        android:theme="@style/Theme.Transparent"
        android:noHistory="true"
        android:excludeFromRecents="true"
        android:label="@string/title_activity_handle_share_intent">
       <intent-filter>
           <action android:name="com.google.android.gm.action.AUTO_SEND"/>
           <action android:name="android.intent.action.SEND"/>
           <action android:name="android.intent.action.SEND_MULTIPLE"/>
           <category android:name="android.intent.category.DEFAULT"/>
           <category android:name="com.google.android.voicesearch.SELF_NOTE"/>
           <data android:mimeType="*/*"/>
       </intent-filter>
    </activity>
    
  2. 活动代码。没有setContentView()finish()onCreate().

    public class HandleShareIntentActivity extends Activity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            startService(new Intent(this, xxxService.class).putExtra(
            Constants.ACTION_SHARE_KEY, getIntent()));
    
            finish();
        }  
     }
    

在 Nexus 5、android 4.4.4 上,我在处理任何共享事件时确实有黑屏闪烁。
有什么解决办法吗?

4

2 回答 2

3

我已经尝试过这个值。

使用Theme.NoDisplay.

于 2014-12-04T13:34:33.537 回答
0

我只是这样做了,它对我的​​情况有所帮助:

<activity
    android:name=".SensorBoardActivity"
    android:theme="@android:style/Theme.NoDisplay"
    android:excludeFromRecents="true"
    android:noHistory="true">

我看到你已经有了finish();,但对于其他人来说,在离开之前执行它很重要onCreate()

于 2018-03-29T11:42:39.320 回答