小编Luk*_*uth的帖子

尝试接收bootcomplete或屏幕关闭时,Android广播接收器无法正常工作

所以我正在尝试开发自定义锁屏

但我的广播接收器不会发射

我的清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="org.alexander.fuchs.lockscreen"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="8" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".app"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <receiver 
            android:name=".myreceiver">
            <intent-filter>
                <action android:name="android.intent.action.SCREEN_OFF"/>
                <action android:name="android.intent.action.SCREEN_ON"/>
                <action android:name="android.intent.action.BOOT_COMPLETED"/>
            </intent-filter>
        </receiver>
    </application>

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

我的接收者:

public class myreceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d("receiver","works");
        Toast.makeText(context,"works",Toast.LENGTH_LONG).show();
        Intent in=new Intent(context,app.class);
         context.startActivity(in);
    }
}
Run Code Online (Sandbox Code Playgroud)

接收器应该告诉我它被触发:D但是它不是logcat中的任何日志

android intentfilter broadcastreceiver android-intent

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

Android:未出现“搜索”对话框

我目前正在尝试在我的应用中实施搜索。我遵循了Google的教程,但是现在,当我按下“搜索”按钮(位于设备/仿真器上)时,什么也没出现。我不知道为什么。

我的searchable.xml文件:

<?xml version="1.0" encoding="utf-8"?>
<searchable
  xmlns:android="http://schemas.android.com/apk/res/android"
    android:label="@string/label_search"
    android:hint="@string/search_hint"
    android:includeInGlobalSearch="true"
  >

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

这是Search-Activity的Android清单部分:

 <!-- Search Activity -->
 <activity android:name=".SearchNotes">
    <intent-filter>
        <action android:name="android.intent.action.SEARCH" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
    <meta-data android:name="android.app.searchable"
        android:resource="@xml/searchable" />
 </activity>
Run Code Online (Sandbox Code Playgroud)

填充我的ListActivity的代码:

private void searchAndDisplay(String query){
    SQLiteDatabase db = db_con.getReadableDatabase();
    final Cursor c = db.rawQuery(
            "SELECT headline, id as '_id' FROM entry WHERE " +
            "(headline LIKE '%?%') OR (content LIKE '%?%') ",
            new String[]{query, query});
    this.startManagingCursor(c);
    final ListAdapter searchAdapter = new SimpleCursorAdapter(
            this, 
            android.R.layout.simple_list_item_2, c, 
            new …
Run Code Online (Sandbox Code Playgroud)

java xml search android android-manifest

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

DataOutputStream写得太多了

我现在有什么

我目前正在尝试用Java创建一个小的下载管理器,我在将一个加载的字节写入文件时遇到了问题.我正在使用a DataOutputStream来编写我从a读取的字节数组DataInputStream.这是我创建的类:

public class DownloadThread extends Thread{

    private String url_s;
    private File datei;

    public DownloadThread(String url_s, File datei){
        this.url_s = url_s;
        this.datei = datei;
    }

    public void run(){
        // Connect:
        int size = 0;
        URLConnection con = null;
        try {
            URL url = new URL(url_s);
            con = url.openConnection();
            size = con.getContentLength();
            // Set Min and Max of the JProgressBar
            prog.setMinimum(0);
            prog.setMaximum(size);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        // Download: …
Run Code Online (Sandbox Code Playgroud)

java

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

PHP:数组排序

我在列表中有大约50个项目.我使用algorythm计算它们的值,然后在数组中添加它们的值.

假设我在循环结束时得到这个:

$vals = (51, 23, 77, 3, 8, 31, 17, 102, 87, (...));
Run Code Online (Sandbox Code Playgroud)

现在,我怎样才能获得数组中3个最高值的键?

在上面的例子中,我想得到:

  • 8(102的关键)
  • 9(87的关键)
  • 3(77的关键)

PS:我不想在数据库中插入这些数据,然后使用Order子句选择它们,我确信有一种更简单的方法.

php

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

检查Boolean.TRUE/Boolean.FALSE是否可以避免装箱/拆箱?

假设我有一个Map<Integer, Boolean>,我想过滤掉所有布尔值为的整数true.这是一些代码:

for (Map.Entry<Integer, Boolean> e : map.entrySet()){
    if (e.getValue() == true){ // Unboxing here
        // Do something useful...
    }
}
Run Code Online (Sandbox Code Playgroud)

在此代码中,Boolean每次执行if时都会将对象取消装箱(如果地图非常大,则可能会出现问题).

现在,Boolean-class提供常量(Boolean.TRUEBoolean.FALSE),它们表示普通的布尔值,true并且false是一个已经装箱的版本(对吧?).因此,使用此代码可以完全避免拆箱:

for (Map.Entry<Integer, Boolean> e : map.entrySet()){
    if (e.getValue() == Boolean.TRUE){ // No Unboxing done (?)
        // Do something useful...
    }
}
Run Code Online (Sandbox Code Playgroud)

我对这个假设是对的吗?或者更糟糕的是两个值都是未装箱的比较?

java boxing unboxing boolean

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