小编Nul*_*ter的帖子

按名称获取线程

我有一个多线程应用程序,我通过setName()属性为每个线程分配一个唯一的名称.现在,我希望功能可以直接使用相应的名称访问线程.

有些功能如下:

public Thread getThreadByName(String threadName) {
    Thread __tmp = null;

    Set<Thread> threadSet = Thread.getAllStackTraces().keySet();
    Thread[] threadArray = threadSet.toArray(new Thread[threadSet.size()]);

    for (int i = 0; i < threadArray.length; i++) {
        if (threadArray[i].getName().equals(threadName))
            __tmp =  threadArray[i];
    }

    return __tmp;
}
Run Code Online (Sandbox Code Playgroud)

上面的函数检查所有正在运行的线程,然后从正在运行的线程集中返回所需的线程.也许我想要的线程被中断,然后上面的功能将无法工作.有关如何整合该功能的任何想法?

java multithreading android

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

在文件下载中实现暂停/恢复

我正在尝试在我的下载管理器中实现暂停/恢复,我搜索网络并阅读几篇文章并根据它们更改我的代码,但恢复似乎无法正常工作,任何想法?

                if (!downloadPath.exists()) 
                    downloadPath.mkdirs(); 

                if (outputFileCache.exists())
                {
                    downloadedSize = outputFileCache.length();
                    connection.setAllowUserInteraction(true);
                    connection.setRequestProperty("Range", "bytes=" + downloadedSize + "-");
                    connection.setConnectTimeout(14000);
                    connection.connect();
                    input = new BufferedInputStream(connection.getInputStream());
                    output = new FileOutputStream(outputFileCache, true);
                    input.skip(downloadedSize); //Skip downloaded size
                }
                else
                {
                    connection.setConnectTimeout(14000);
                    connection.connect();
                    input = new BufferedInputStream(url.openStream());
                    output = new FileOutputStream(outputFileCache);
                }

                fileLength = connection.getContentLength();                 


                byte data[] = new byte[1024];
                int count = 0;
                int __progress = 0;
                long total = downloadedSize;

                while ((count = input.read(data)) != -1 && !this.isInterrupted()) 
                {
                    total += count;
                    output.write(data, 0, …
Run Code Online (Sandbox Code Playgroud)

java android download

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

将淡化边缘应用于ImageView

有没有办法将垂直/水平渐变边应用于ImageView组件?

我已经尝试了android:fadingEdge但不幸的是这个属性已被弃用,从API级别14开始将被忽略,任何想法?

java xml android fade imageview

5
推荐指数
2
解决办法
5194
查看次数

服务被杀死时销毁前台通知

我有一个前台服务从网上下载一些内容.

不幸的是,由于在这里报告的bug 我的服务在接收器收到我的服务中的广播时被杀死但它的通知不会被杀死我看到我的logcat中的以下日志:

I/ActivityManager(449): Killing 11073:my-package-name/u0a102 (adj 0): remove task
Run Code Online (Sandbox Code Playgroud)

无论如何在它的父服务被OS杀死时销毁前台通知?

java android

5
推荐指数
1
解决办法
1956
查看次数

自定义操作项ActionBarSherlock

我正在尝试向我添加一些自定义操作ActionBar,是否可以使用自定义布局实现这些操作?因为我想在这些操作中添加一些徽章,例如通知计数器.

例如

在此输入图像描述

知道怎么做到这一点?

android actionbarsherlock android-actionbar

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

ViewPager具有固定宽度的子项

我需要设计一个ViewPager能够传递固定宽度的孩子(例如宽度为700dp的孩子),不幸的是当前版本ViewPager会自动使所有孩子的宽度为MATCH_PARENT,是否有任何方法可以添加此功能ViewPager

我的ViewPager布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <android.support.v4.view.ViewPager
        android:id="@+id/some_id"
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:overScrollMode="never" />

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

ViewPager 孩子布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/banner_main_layout_container"
    android:layout_width="700dp"
    android:layout_height="match_parent"
    android:background="#fff"
    android:gravity="center"
    android:orientation="vertical" >

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="some images"/>

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

提前致谢...

android android-viewpager

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

currentTimeMillis()4小时

我有一个简单的问题,我有以下功能,并且有关于它的参数调用cacheTime,如何将其设置为4小时,我应该将其设置为4 * 3600000

public static File getCache(String name, Context c, int cacheTime) 
{
    if (cacheTime <= 0)
        return null;
    File cache = new File(c.getCacheDir(), name);
    long now = System.currentTimeMillis();
    if (cache.exists() && (now - cache.lastModified() < cacheTime))
        return cache;
    return null;
}
Run Code Online (Sandbox Code Playgroud)

java android

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

与not()函数相反

我有一个简单的问题,我有以下几行等于非活动链接:

$links.not($active).each(function() 
{
     //Do sth...
});
Run Code Online (Sandbox Code Playgroud)

.not(...)JavaScript 中的函数相反的是什么?因为我需要知道活动链接,任何想法!

javascript jquery

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

API 8的getNumColumns()

getNumColumns()for GridViewAPI自API 11起可用,有没有办法在API 8中获得此方法?

android gridview

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

加入UTF-8字符串

我想加入一些UTF-8字符串,任何想法?

例如:

输入:س+ل+ا+م

输出:سلام

javascript string utf-8

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

使用RoboSpice执行Parellel

通过异步执行一堆请求的最简单方法是RoboSpice什么?

我在某处读到了我需要实现的RequestRunner但是我不知道将它合并的方式SpiceManager,任何想法?

android robospice

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