我的活动检查互联网连接并显示ProgresDialog(如果有连接)。 现在,如果显示ProgressdlDialog并且互联网连接不可用,那么可怜的ProgressDialog会一直加载到enternity。 所以,我想检测progressdialog的状态;然后显示AlertDialog,如果它的加载和互联网连接不可用。
答案 0 :(得分:1)
您可以使用CONNECTIVITY_CHANGE Receiver来了解连接何时更改,而不是使用方法来使用以下代码获取连接的实际状态:
ConnectivityManager cm =
(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
boolean isConnected = activeNetwork != null &&
activeNetwork.isConnectedOrConnecting();
http://viralpatel.net/blogs/android-internet-connection-status-network-change/
答案 1 :(得分:0)
检测ProgressDialog
let arr0:[Int?]? = [1,2,3]
if let r = arr0 where r.dynamicType == [Int].self {
print(r, r.dynamicType)
} else {
print("not [Int]")
}
// prints
// not [Int]
// but
func foo()->[Int] {
let arr0:[Int?]? = [1,2,3]
if let r = arr0 where r.dynamicType == [Int].self {
print(r, r.dynamicType)
// !!!!! ERROR !!!!!
// next line doesn't compile wihout flatMap !!!!
//
// error: cannot convert return expression of type '[Int?]' to return type '[Int]'
//
// even though that it is clear from the where clause that r type must be [Int]
return r.flatMap{ $0 }
} else {
print("arr0 is not [Int]")
return []
}
}
foo() // [] and prints: arr0 is not [Int]