2个问题:
>如何在没有用户设置或需要交互的情况下自动启动程序(服务)进行初始化?
>我的印象是,如果不使用Activity,就无法实例化和显示对话框.我希望对话框显示在用户当前在屏幕上的任何内容上,并显示一个对话框.有没有办法让Activity对当前Activity完全透明,或者有没有办法从服务中显示对话框?
提前致谢.
解决方法
How do I get the program (Service) to initialize at boot automatically with no user setting or interaction required?
将此权限添加到清单:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />然后在清单中添加一个接收器:
<receiver android:name="your.package.BootReceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> <category android:name="android.intent.category.HOME" /> </intent-filter> </receiver>用Java代码创建接收器:
public class BootReceiver extends BroadcastReceiver { @Override public void onReceive(Context context,Intent intent) { // start the service from here } }I was under the impression that you cannot instantiate and display dialogs without using an Activity. I would like the dialogs to appear laid over whatever the user currently has on the screen,and display a dialog. Is there a way to make an Activity completely transparent over the current Activity or is there a way to display dialogs from a Service?
是的,这是真的.您必须有一个弹出对话框的活动.要创建透明活动,请在res / values / styles.xml文件中添加以下样式(如果没有,请创建它.)这是一个完整的文件:
<?xml version="1.0" encoding="utf-8"?> <resources> <style name="Theme.Transparent" parent="android:Theme"> <item name="android:windowIsTranslucent">true</item> <item name="android:windowBackground">#00000000</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>然后将样式应用于您的活动,例如:
<activity android:name=".TransparentActivity" android:theme="@style/Theme.Transparent"> ... </activity>