在点击按钮我想用方法来启动服务startService(new Intent(currentActivity.this,MyService.class)),但如果服务正在运行,我不想把这种方法做,以避免运行服务,已经running.How这possible.I是同时使用意向的服务和服务在同一项目并希望为两者应用相同的条件.
在parcel的情况下,我找不到任何有关如何处理整数数组的解决方案(我想使用这两个函数dest.writeIntArray(storeId); 和 in.readIntArray(storeId);).
这是我的代码
public class ResponseWholeAppData implements Parcelable {
private int storeId[];
public int[] getStoreId() {
return storeId;
}
public void setStoreId(int[] storeId) {
this.storeId = storeId;
}
@Override
public int describeContents() {
return 0;
}
public ResponseWholeAppData(){
storeId = new int[2];
storeId[0] = 5;
storeId[1] = 10;
}
public ResponseWholeAppData(Parcel in) {
if(in.readByte() == (byte)1)
in.readIntArray(storeId); //how to do this storeId=in.readIntArray(); ?
}
}
@Override
public void writeToParcel(Parcel dest, int flags) {
if(storeId!=null&&storeId.length>0)
{
dest.writeByte((byte)1);
dest.writeIntArray(storeId); …Run Code Online (Sandbox Code Playgroud) 我正在实施GCM.我的应用程序有两个活动,比如说A和B.我正在使用此代码B从NotificationBar 启动:
long when = System.currentTimeMillis();
NotificationManager notificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
String title = context.getString(R.string.app_name);
Notification notification = new Notification(R.drawable.app_notification_icon, "De Centrale", when);//message
Intent notificationIntent = new Intent(context, B.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); //|Intent.FLAG_ACTIVITY_REORDER_TO_FRONT
PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);
notification.setLatestEventInfo(context, title, msg, intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, notification);
Run Code Online (Sandbox Code Playgroud)
NotificationBar打开活动B,意图,说"B-通知意向",然后我打开活动A从B使用后退按钮,然后重新启动我B从A有一个新的intent(说"BA-意图").我使用下面的代码:
intent = new Intent(this, B.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
然后我获得新数据B(即B刷新的屏幕).但是,如果我按下主页按钮,然后我从最近的应用程序启动应用程序,那么我会 …
我使用此代码获取地理地址:
private String getAddress(Location location)
{
try{
List<Address> addresses = new Geocoder(this,Locale.getDefault()).getFromLocation(location.getLatitude(), location.getLongitude(), 1);
if(addresses!=null)
{
String address="Address not available";
for(int i=0;i<addresses.size();i++)
{
Address addre=addresses.get(i);
String street=addre.getAddressLine(0);
if(null==street)
street="";
String city=addre.getLocality();
if(city==null) city="";
String state=addre.getAdminArea();
if(state==null) state="";
String country=addre.getCountryName();
if(country==null) country="";
address=street+", "+city+", "+state+", "+country;
}
return address;
}
}
catch (Exception e) {
return "Address not available";
}
return "Address not available";
}
Run Code Online (Sandbox Code Playgroud)
早些时候我收到了一个地址列表,但现在我每次都得到这个例外:
java.io.IOException unable to parse response from server
Run Code Online (Sandbox Code Playgroud)
请帮忙.
我正在开发一个Android应用程序.如果屏幕关闭,我发现GPS无法在某些设备(Samsung Galaxy S 2.2.1版,Samsung Galaxy Ace版2.3.6 Gingerbread,Motorola Diffy 2.2)上运行.即使屏幕关闭,它在其他设备(HTC Wildfire 2.3.3)上也能正常工作.为什么是这样?
我想在JSonArray中将对象添加到特定位置.我的当前JsonArray看起来像这样
{
"imgs": [
"String1",
"String2",
"String3",
"String4"
]
}
Run Code Online (Sandbox Code Playgroud)
我需要在第一个位置的jsonarray中插入一个项目,如下所示 -
jsonArray.put(1,"String5")
Run Code Online (Sandbox Code Playgroud)
这是在第一个位置替换项目但我需要在下面的结果
{
"imgs": [
"String1",
"String5",
"String2",
"String3",
"String4"
]
}
Run Code Online (Sandbox Code Playgroud)
请建议
如果textview变成两行,我在textview之后放置imageview会遇到问题.我想显示这个(图片刚好在文字后面,文字可以在一行,两行或三行)
如果文本很短(一行),我的imageview就在textview之后.但是当文本变得更长(两行)时,图像会像这样进入下一行
我知道这个问题的原因但不知道如何解决?
我正在与服务提供商进行通信失败:收到的身份验证质询为空
我想打开Play商店设置页面.虽然我知道如何打开游戏商店
final String appName = "";
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id="+appName)));
} catch (android.content.ActivityNotFoundException anfe) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id="+appName)));
}
Run Code Online (Sandbox Code Playgroud)
但我想打开看起来像这个图像的播放商店设置(将用户重定向到自动更新选项)页面

怎么做.这有什么意图吗?
我试图在我的Android应用程序中实现Facebook SSO。它将打开本机Facebook应用程序,登录过程完成后显示“ 500:内部服务器错误”。我在做什么错?
任何建议将不胜感激。这是我的代码
public class FacebookUtil {
public static Facebook facebook = new Facebook(AppConstants.FACEBOOK_APP_ID);
String FILENAME = "AndroidSSO_data";
private static SharedPreferences mPrefs;
private static Context mContext;
private static boolean isSucess;
private static FacebookSucessListener mFacebookSucessListener;
public static final String FB_APP_SIGNATURE ="xxxxxxxxxxxxxxxxxxx";
public interface FacebookSucessListener {
public void onSucess(boolean isSucess);
}
public static void postToWall(){
facebook.dialog(mContext, "feed" , new DialogListener(){
public void onCancel() {
}
public void onComplete(Bundle arg0) {
}
public void onError(DialogError arg0) {
}
public void onFacebookError(FacebookError arg0) …Run Code Online (Sandbox Code Playgroud) 我在转换Date为毫秒时遇到问题
try {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd, HH:mm:ss");
formatter.setLenient(false);
String oldTime = "2013-06-11 06:40:24";
Date oldDate;
oldDate = formatter.parse(oldTime);
Sysout(oldDate.getTime());
} catch (ParseException e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
它扔了一个Parsing Exception.