使用Tabs,Wifi和Gps

时间:2011-04-28 15:59:49

标签: android gps tabwidget android-wifi

1 个答案:

答案 0 :(得分:0)

要在主线程中调用WI-FI和GPS,而不是在子线程中调用..
所以在main.java中,

try{  
   // Setup WiFi  
   wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);  
   locationManager = (LocationManager)   getSystemService(Context.LOCATION_SERVICE);  
   if (receiver == null)  
       receiver = new WiFiFilter(this);                
   registerReceiver(receiver, new IntentFilter(  
                  WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));  
   if (locationListener ==null ){
       locationListener=new gpsLocation(this);
       } 
   }  
   catch(Exception e){
       Toast.makeText(context, WIFI_SERVICE, Toast.LENGTH_LONG).show();
   }  
}     

将放置以前在start.java中初始化的名称

  

通过执行此操作,不会杀死重要的进程并阻止应用程序崩溃。