小编may*_*ysi的帖子

PendingIntent不会发送Intent附加内容

MainActicity 开始RefreshServiceIntent具有boolean所谓的多余isNextWeek.

RefreshService做了一个在用户点击它时Notification启动我MainActivity的.

这看起来像这样:

    Log.d("Refresh", "RefreshService got: isNextWeek: " + String.valueOf(isNextWeek));

    Intent notificationIntent = new Intent(this, MainActivity.class);
    notificationIntent.putExtra(MainActivity.IS_NEXT_WEEK, isNextWeek);

    Log.d("Refresh", "RefreshService put in Intent: isNextWeek: " + String.valueOf(notificationIntent.getBooleanExtra(MainActivity.IS_NEXT_WEEK,false)));
    pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

    builder = new NotificationCompat.Builder(this).setContentTitle("Title").setContentText("ContentText").setSmallIcon(R.drawable.ic_notification).setContentIntent(pendingIntent);
    notification = builder.build();
    // Hide the notification after its selected
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notificationManager.notify(NOTIFICATION_REFRESH, notification);
Run Code Online (Sandbox Code Playgroud)

你可以看到notificationIntent应该有boolean额外IS_NEXT_WEEK的值,isNextWeek其中放入了PendingIntent.

当我现在点击这个时, …

android android-intent android-service android-pendingintent

117
推荐指数
2
解决办法
4万
查看次数

Android Studio:Gradle - 构建失败 - 任务'执行失败':dexDebug'

错误:

Gradle: Execution failed for task ':vertretungsplan:dexDebug'.
> Failed to run command:
    P:\Android-Studio\sdk\build-tools\18.0.1\dx.bat --dex --output P:\Projekte\VertretungsplanProject\vertretungsplan\build\libs\vertretungsplan-debug.dex P:\Projekte\VertretungsplanProject\vertretungsplan\build\classes\debug P:\Projekte\VertretungsplanProject\vertretungsplan\build\dependency-cache\debug P:\Android-Studio\sdk\extras\android\m2repository\com\android\support\support-v4\18.0.0\support-v4-18.0.0.jar P:\Projekte\VertretungsplanProject\vertretungsplan\libs\commons-io-2.4.jar P:\Projekte\VertretungsplanProject\vertretungsplan\build\exploded-bundles\VertretungsplanProjectLibrariesActionbarsherlockUnspecified.aar\classes.jar
Error Code:
    2
Output:
    trouble processing:
    bad class file magic (cafebabe) or version (0033.0000)
    ...while parsing de/MayerhoferSimon/Vertretungsplan/LoginActivity$2.class
    ...while processing de/MayerhoferSimon/Vertretungsplan/LoginActivity$2.class
    trouble processing:
    bad class file magic (cafebabe) or version (0033.0000)
    ...while parsing de/MayerhoferSimon/Vertretungsplan/MainActivity$1.class
    ...while processing de/MayerhoferSimon/Vertretungsplan/MainActivity$1.class
    trouble processing:
    bad class file magic (cafebabe) or version (0033.0000)
    ...while parsing de/MayerhoferSimon/Vertretungsplan/YQL/YqlVplanParser.class
    ...while processing de/MayerhoferSimon/Vertretungsplan/YQL/YqlVplanParser.class
    3 warnings
    UNEXPECTED TOP-LEVEL EXCEPTION:
    com.android.dx.util.DexException: Multiple …
Run Code Online (Sandbox Code Playgroud)

android gradle android-studio android-gradle-plugin

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

为什么FrameLayout用于片段?

无论我在哪里,FrameLayout似乎都被用作FragmentContainer.为什么FrameLayout总能看到Fragments

java android fragment android-framelayout

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

Android中静态变量的生命周期

当我在主活动中声明并初始化变量为静态并且活动被销毁时.我还可以访问变量的内容吗?

例如,要始终访问我存储到此变量的AsyncTask?我想要的是能够在方向改变后访问它.

java static android

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

如何在android中使用合约类?

我有点困惑,因为我不知道如何解释这个教程:http://developer.android.com/training/basics/data-storage/databases.html#DbHelper

我的代码到现在看起来像这样:

public final class DatabaseContract {
// To prevent someone from accidentally instantiating the contract class,
// give it an empty constructor.
public DatabaseContract() {}

public static abstract class Table1 implements BaseColumns {
    public static final String TABLE_NAME       = "nameOfTable";
    public static final String COLUMN_NAME_COL1 = "column1";
    public static final String COLUMN_NAME_COL2 = "column2";
    public static final String COLUMN_NAME_COL3 = "column3";
}

public class DatabaseHelper extends SQLiteOpenHelper {
    // If you change the database schema, you …
Run Code Online (Sandbox Code Playgroud)

java sql database android save

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

IntentService创建的通知始终使用错误的Intent

问题

当用户按下Send "Button 1"(向下滚动以查看应用程序的构造)时,将Notification创建一个新的RefreshService.如果用户按下此通知,则MainActivity实例启动并接收String具有Button 1超过该值的值Intent.

显示该值.

当用户现在按下时,Send "Button 2"Notification创建一个新的RefreshService.如果用户按下此通知,则会MainActivity启动一个实例,并接收一个ALSO值超过该值的ALSO.String Button 1Intent

所以你可以猜测,通常应该有价值Button 2.

当用户按下的第一个按钮时,Send "Button 2"总会Button 2发送.

获得第二个按钮值的唯一解决方案是重新启动手机并先按下第二个按钮.即使强行关闭也行不通.

我知道我也可以用另一种方式更改UI.但是我需要在应用程序中使用这种方法,我需要用另一个重新启动'MainActivity',Intent因此方法应该是相同的.

施工

主要活动

public class MainActivity extends Activity implements View.OnClickListener {
    public static final String RECEIVED = "received"; …
Run Code Online (Sandbox Code Playgroud)

android android-intent android-notifications intentservice android-activity

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

小部件中的ListView在滚动和调整大小时添加随机项(嵌套的远程视图)

更新:我创建了一个包含较少代码的存储库,以使其更容易理解.

我正在尝试创建一个小部件.我就像这里描述的那样:https://stackoverflow.com/a/6093753/2180161

它部分工作,但我有一个非常奇怪的错误.我做了一个截屏视频,所以更容易理解我的意思:http: //c.maysi.de/c6H9

截图: 在此输入图像描述

如您所见,有一些项目是随机添加的.(RemoteViews已添加到另一个RemoteViews对象) 当我调整窗口小部件时,会发生同样的情况.

我在日志中打印的内容与预期的一样.没有错误的数据.滚动时也没有新的日志条目.

这是我的代码:

RemoteViewsFactory:

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class MyWidgetViewsFactory implements RemoteViewsService.RemoteViewsFactory {
    private static ArrayList<Item> items = new ArrayList<>();
    private static int itemnr = 0;
    private static int subitemnr = 0;
    private int appWidgetId;
    private Context context;

    public MyWidgetViewsFactory(Context context, Intent intent) {
        this.context = context;
        appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
                AppWidgetManager.INVALID_APPWIDGET_ID);


        //Some random data to display
        for (int i = …
Run Code Online (Sandbox Code Playgroud)

android listview android-widget android-listview android-appwidget

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

Android Studio启动时出现Gradle错误

每次启动Android Studio时都会出现以下错误:

Gradle'VertretungsplanProject'项目刷新失败:无法使用Gradle发行版" http://services.gradle.org/distributions/gradle-1.6-bin.zip " 获取"IdeaProject"类型的模型.配置项目':Vertretungsplan'时出现问题.配置项目':Vertretungsplan'时出现问题.无法通知项目评估监听器.配置项目':libraries:actionbarsherlock'时出现问题.无法通知项目评估监听器.无法规范化文件'P:\ Projekte\VertretungsplanProject\libraries\actionbarsherlock:Vertretungsplan\libs\android-support-v4.jar'的路径.文件名,目录名或卷标的语法错误

我的项目看起来像这样:

在此输入图像描述

Gradle设置:

在此输入图像描述

build.gradle of :Vertretungsplan:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.5.+'
    }
}
apply plugin: 'android'

dependencies {
    compile files('libs/commons-io-2.4.jar')
    compile project(':libraries:actionbarsherlock')
}

android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"

    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 16
    }
}
Run Code Online (Sandbox Code Playgroud)

build.gradle :VertretungsplanProject为空.

build.gradle :actionbarsherlock:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.5.+'
    }
}
apply plugin: 'android-library'

dependencies {
    compile files(':Vertretungsplan/libs/android-support-v4.jar')
}

android {
    compileSdkVersion 17
    buildToolsVersion …
Run Code Online (Sandbox Code Playgroud)

gradle android-support-library android-studio build.gradle

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

如何检查字符串是否与特定格式匹配?

我想检查一个字符串是否只是mytches以下格式:

"00-00"
Run Code Online (Sandbox Code Playgroud)

字符串中应该没有空格,破折号前面只有2个数字,破折号后面只有2个数字.

最好的方法是什么?

java string

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

如何在div中使用带有文本的clip-path?

我尝试了以下方法:

http://codepen.io/anon/pen/YXePBY

<div>lorem ipsum dolor sit amet lorem ipsum dolor sit amet lorem ipsum dolor sit amet lorem ipsum dolor sit amet lorem ipsum dolor sit amet lorem ipsum dolor sit amet lorem ipsum dolor sit amet lorem ipsum dolor sit amet lorem ipsum dolor sit amet</div>

div {
    width: 280px;
    height: 280px;
    background: #1e90ff;
    -webkit-clip-path: polygon(0 0, 78% 0, 93% 99%, 0% 100%);
  clip-path: polygon(0 0, 78% 0, 93% 99%, 0% 100%);
  padding: 15px
}

/* Center the demo …
Run Code Online (Sandbox Code Playgroud)

html css css3

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