监听网络状态的改变 :
权限 : <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
public class MyBroastCast extends BroadcastReceiver {
private static final String ACTION = "android.net.conn.CONNECTIVITY_CHANGE";
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(ACTION)){
Intent i= new Intent(context, XXXService.class);
context.startService(i);
}
}
}
XXXService为你的Service
AndroidManifest.xml中添加:
<receiver android:name=".MyBroastCast">
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
</receiver>
横竖屏切换时,Dialog不会消失的配置:
<activity>android:configChanges="navigation|orientation|keyboardHidden"