@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ButterKnife.inject(this); mapView.addLayer( new ArcGISTiledMapServiceLayer( "http://cache1.arcgisonline.cn/ArcGIS/rest/services/ChinaOnlineCommunity/MapServer")); layer = new GraphicsLayer(); mapView.addLayer(layer); mapView.getLocationDisplayManager().start(); mapView.getLocationDisplayManager().setLocationListener(this); try { client = new MqttAndroidClient( this, "tcp://broker.mqttdashboard.com:1883", "Likaci/MqttMap/" + id); client.setCallback(this); MqttConnectOptions options = new MqttConnectOptions(); options.setKeepAliveInterval(10); options.setConnectionTimeout(1000); options.setCleanSession(false); client.connect(options, null, this); } catch (Exception e) { e.printStackTrace(); } }