小编wes*_*ton的帖子

如何确定应用程序的方法计数?

我遇到了我的应用程序有太多方法的问题.

在下面链接的最后一篇文章中,海报张贴了他的申请的方法计数(按包分类).我无法找到如何为我的应用程序获取此信息,任何建议?

https://code.google.com/p/android/issues/detail?id=20814

java android

18
推荐指数
5
解决办法
9489
查看次数

如何在不调整大小的情况下从res加载位图?

使用此代码:

    Drawable blankDrawable = context.getResources().getDrawable(image);
    Bitmap blankBitmap=((BitmapDrawable)blankDrawable).getBitmap();
Run Code Online (Sandbox Code Playgroud)

我得到一个缩放到上下文密度的位图,保留位图的物理大小(基于其dpi值).例如,我有一个405x500位图(dpi = 96)作为资源.但是当我将它加载到设备上时,我得到一张密度= 240的608x750图像.我想加载位图而不进行缩放.我怎么做?

这个问题非常类似于:

如何在不调整大小的情况下从流创建Drawable?

但是,在我的情况下不能使用该解决方案,因为我没有输入流.我所拥有的只是一个资源ID,而getDrawable()方法没有密度参数.加载位图后,为时已晚 - 它已经调整大小.

谢谢.

android bitmap

17
推荐指数
4
解决办法
3万
查看次数

保持服务正常运行

当用户关闭服务时,有人能告诉我保持服务始终运行或重新启动的方法吗?当我清除内存时,我看到facebook服务重启了.我不想制作ForegroundServices.

service android

16
推荐指数
2
解决办法
3万
查看次数

绘制/布局期间的对象分配?

在绘制/布局期间,我得到3个对象分配警告

super.onDraw(canvas);
canvas.drawColor(Color.WHITE);
Paint textPaint = new Paint();
textPaint.setARGB(50,100,100,250);
textPaint.setTextAlign(Align.CENTER);
textPaint.setTextSize(50);
textPaint.setTypeface(font);
canvas.drawText("Logan is awesom",canvas.getWidth()/2,200,textPaint);
canvas.drawBitmap(pBall, (canvas.getWidth()/2), changingY, null);
if (changingY <canvas.getHeight()){
changingY += 10;
}else{
changingY=0;
}
Rect middleRect = new Rect();
middleRect.set(0, 400, canvas.getWidth(), 550);
Paint ourBlue = new Paint();
ourBlue.setColor(Color.BLUE);
canvas.drawRect(middleRect, ourBlue);
Run Code Online (Sandbox Code Playgroud)

我在新的Rect()上遇到错误; 并在新的Paint();

确切的错误是在绘制/布局操作期间避免对象分配(预定位和重用)

java android

16
推荐指数
1
解决办法
1万
查看次数

为什么每个Char静态"Is ..."都有一个字符串重载,例如IsWhiteSpace(string,Int32)?

http://msdn.microsoft.com/en-us/library/1x308yk8.aspx

这允许我这样做:

var str = "string ";
Char.IsWhiteSpace(str, 6);
Run Code Online (Sandbox Code Playgroud)

而不是:

Char.IsWhiteSpace(str[6]);
Run Code Online (Sandbox Code Playgroud)

看起来很不寻常,所以我看了一下反思:

[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
public static bool IsWhiteSpace(char c)
{
    if (char.IsLatin1(c))
    {
        return char.IsWhiteSpaceLatin1(c);
    }
    return CharUnicodeInfo.IsWhiteSpace(c);
}

[SecuritySafeCritical]
public static bool IsWhiteSpace(string s, int index)
{
    if (s == null)
    {
        throw new ArgumentNullException("s");
    }
    if (index >= s.Length)
    {
        throw new ArgumentOutOfRangeException("index");
    }
    if (char.IsLatin1(s[index]))
    {
        return char.IsWhiteSpaceLatin1(s[index]);
    }
    return CharUnicodeInfo.IsWhiteSpace(s, index);
}
Run Code Online (Sandbox Code Playgroud)

三件事让我印象深刻:

  1. 为什么只在上限进行限制检查呢?抛出一个ArgumentOutOfRangeException,而索引低于0将给出字符串的标准IndexOutOfRangeException
  2. 的precense SecuritySafeCriticalAttribute我读过关于一般blerb,但在这里做什么还不清楚,如果它链接到上限检查. …

c#

15
推荐指数
1
解决办法
276
查看次数

Environment.getExternalStoragePublicDirectory提供内部存储

我正在保存这样一张照片:

File dcimDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
File picsDir = new File(dcimDir, "MyPics");
picsDir.mkdirs(); //make if not exist
File newFile = new File(picsDir, "image.png"));
OutputStream os;
try {
    os = new FileOutputStream(newFile);

    target.compress(CompressFormat.PNG, 100, os);

    os.flush();
    os.close();
    b.recycle();
} catch (FileNotFoundException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)

但是,当我通过Windows查找图像时,它位于内部存储器中,图库确认了这一点:

在PC上

画廊细节

最后一个是令人困惑的,它说内部存储器,但后来也有sdcard0文件路径.

那么外部什么时候不代表外部?它是设备设置的东西,还是我错过使用/错过理解getExternalStoragePublicDirectory

android

15
推荐指数
1
解决办法
3万
查看次数

System.out字符编码

我正在从命令行运行我的Java程序(Windows 7).为简化问题,我仅描述相关部分.

public static void main(String[] args) {
    System.out.println("Árpád");
}
Run Code Online (Sandbox Code Playgroud)

我的输出是垃圾.这显然是一个字符编码问题,Á和á的匈牙利字符没有正确显示.我尝试过以下方法:

public static void main(String[] args) {
    PrintStream ps = new PrintStream(System.out, true, "UTF-8");
    ps.println("Árpád");
}
Run Code Online (Sandbox Code Playgroud)

但我的输出仍然是垃圾.如何使用Windows 7命令行解决此字符编码问题?谢谢

java character-encoding windows-7

14
推荐指数
1
解决办法
1万
查看次数

APP_OPTIM如何在代码中显示?

在Application.mk中,您可以设置:

APP_OPTIM := release
APP_OPTIM := debug
Run Code Online (Sandbox Code Playgroud)

如何在C++中测试发布/调试版本?

我假设有定义所以我试过这个,但只记录"NOT"消息:

#ifdef RELEASE
    LOGV("RELEASE");
#else
    LOGV("NOT RELEASE");
#endif

#ifdef DEBUG
    LOGV("DEBUG");
#else
    LOGV("NOT DEBUG");
#endif
Run Code Online (Sandbox Code Playgroud)

android-ndk

13
推荐指数
1
解决办法
7294
查看次数

成员变量和本地方法变量可以具有相同的名称吗?

我怎么做到这一点?

class Test {
    private int var1;

    public Test(int var1) {
        var1 = var1; //set the member variable to what was passed in
    }
}
Run Code Online (Sandbox Code Playgroud)

我相信有一个非常明显的答案.它现在正在逃避我.

java variables syntax

12
推荐指数
2
解决办法
7549
查看次数

排序列表并在排序后将特定元素保留在列表的末尾

我有一个包含字符串的列表"Others".我得到这个列表下拉.我按字母顺序排序这个列表.但我"Others"总是需要在列表的末尾.我不想在排序后添加这个元素,这是一个解决方案.有没有其他方法可以像使用.Sort()方法的自定义比较器一样.我试过下面但没有解决方案.

 public class EOComparer : IComparer<string>
    {
        public int Compare(string x, string y)
        {
            if (x == null)
            {
                if (y == null)
                {
                    // If x is null and y is null, they're
                    // equal. 
                    return 0;
                }
                else
                {
                    // If x is null and y is not null, y
                    // is greater. 
                    return -1;
                }
            }
            else
            {
                // If x is not null...
                //
                if (y == null)
                // ...and …
Run Code Online (Sandbox Code Playgroud)

c# linq sorting list

12
推荐指数
2
解决办法
4227
查看次数