StackOverfow 上有很多类似的问题,但它们并没有解决我的问题。
任务是处理来自不同应用程序的使用默认共享机制(ACTION_SEND)发送的服务意图。
但就ACTION_SEND
活动而言,我们必须在活动中获取意图并将其广播到服务中。如果此活动对用户不可见,那将是完美的。
我已经研究了很多,并且已经尝试了很多解决方案。
使活动隐形的第一步属于活动风格。
我已经尝试过这个值。
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>
活动代码。没有
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 上,我在处理任何共享事件时确实有黑屏闪烁。
有什么解决办法吗?