我已经实现了PubNub订阅和发布代码.我的代码在活动上运行良好.但现在我想在服务类的帮助下在后台执行该代码.我创建了我的课程扩展IntentService
.我订阅了onCreate
方法中的pubnub频道.但每当我运行应用程序服务时,会立即停止而不显示pubnub状态.我正在关注pubnub错误.我也链接了pubnub所需的库.
04-09 23:39:32.621: D/Service Message(10033): error[Error: 100-1] : Timeout Occurred
Run Code Online (Sandbox Code Playgroud)
MainActivity.java
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void startService(View v){
startService(new Intent(this, MyService.class));
}
public void stopService(View v){
stopService(new Intent(this, MyService.class));
}
}
Run Code Online (Sandbox Code Playgroud)
PubnubHandler.java
public class PubnubHandler{
public static final String GLOBAL_CHANNEL = "my_channel_name";
public static final String PUBLISH_KEY =
"my_publish_key";
public static final String SUBSCRIBE_KEY =
"my_subscribe_key";
private Context context;
private Pubnub pubnub;
public PubnubHandler(Context …
Run Code Online (Sandbox Code Playgroud) 我想使用Android中的“共享首选项”保存数据。但是我希望使用单独的类来完成此任务。我已经像下面这样实现了该类,
import android.content.Context;
import android.content.SharedPreferences;
public class SavePref {
private Context context;
public SavePref(Context context){
this.context = context;
}
public void saveInt(String key, int value) {
SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();
editor.putInt(key, value);
editor.commit();
}
}
Run Code Online (Sandbox Code Playgroud)
但是,上有一个错误getActivity()
,
The method getActivity() is undefined for the type SavePref
Run Code Online (Sandbox Code Playgroud)
如何解决呢?
谢谢
我在我的应用程序开发中使用 Google Map API V2。在默认放大的初始条件下显示地图没有任何问题。但是当我尝试放大地图时,它没有按照我的意愿进行更新。当我放大更多时,它只是空白地图,没有在那里加载任何东西。我正在等待加载,但没有响应。
谢谢。
爪哇
// Google Map Initialization
try {
if (googleMap == null) {
googleMap = ((SupportMapFragment) getSupportFragmentManager().
findFragmentById(R.id.map)).getMap();
}
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
googleMap.setMyLocationEnabled(true);
} catch (Exception e) {
e.printStackTrace();
}
// Google Map Initialization ends
// Google Map Manipulation
MapTypeChange.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
if(googleMap.getMapType() == GoogleMap.MAP_TYPE_TERRAIN) {
googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
MapTypeChange.setText("Terrain");
}
else {
googleMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
MapTypeChange.setText("Satellite");
}
}
});
googleMap.addMarker(new MarkerOptions()
.position(new LatLng(10, 10))
.title("Gaurav"))
.showInfoWindow();
googleMap.addMarker(new MarkerOptions()
.position(new …
Run Code Online (Sandbox Code Playgroud) java android android-layout android-fragments google-maps-android-api-2