小编Suj*_*ala的帖子

通知传递旧的Intent Extras

我通过以下代码在BroadcastReceiver中创建通知:

String ns = Context.NOTIFICATION_SERVICE;
        NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns);
        int icon = R.drawable.ic_stat_notification;
        CharSequence tickerText = "New Notification";
        long when = System.currentTimeMillis();

        Notification notification = new Notification(icon, tickerText, when);
        notification.defaults |= Notification.DEFAULT_VIBRATE;
        long[] vibrate = {0,100,200,200,200,200};
        notification.vibrate = vibrate;
        notification.flags |= Notification.FLAG_AUTO_CANCEL;

        CharSequence contentTitle = "Title";
        CharSequence contentText = "Text";
        Intent notificationIntent = new Intent(context, NotificationActivity.class);
        notificationIntent.putExtra(Global.INTENT_EXTRA_FOO_ID, foo_id);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

        notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);

        int mynotification_id = 1;

        mNotificationManager.notify(mynotification_id, notification);
Run Code Online (Sandbox Code Playgroud)

当我点击通知时,它会打开NotificationActivity,在Activity中我可以从Intent-Bundle中检索foo_id(例如1)

但是,如果触发另一个通知并再次单击它,则活动仍会从Intent-Bundle接收"旧"值(1).我试图用clear()清除包,但收到的效果相同.我觉得我的代码错了......

android android-notifications android-notification-bar android-pendingintent

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

Angular 2组件构造函数与OnInit

如果我希望每次加载组件时都会发生函数x,无论是第一次加载,我都会导航到另一个站点并导航回来,或者是组件第五次加载.

我应该把函数x放入什么?组件构造函数还是OnInit?

constructor ngoninit angular

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

Angular2的ngOnInit和ngAfterViewInit有什么区别?

我无法理解ngOnInit和之间的区别ngAfterViewInit.

我发现它们之间唯一的区别是@ViewChild.根据以下代码,elementRef.nativeElement其中的内容是相同的.

我们应该使用什么场景ngAfterViewInit

@Component({
  selector: 'my-child-view',
  template: `
  <div id="my-child-view-id">{{hero}}</div>
  `
})
export class ChildViewComponent {
  @Input() hero: string = 'Jack';
}

//////////////////////
@Component({
  selector: 'after-view',
  template: `
    <div id="after-view-id">-- child view begins --</div>
      <my-child-view [hero]="heroName"></my-child-view>
    <div>-- child view ends --</div>`
   + `
    <p *ngIf="comment" class="comment">
      {{comment}}
    </p>
  `
})
export class AfterViewComponent implements AfterViewInit, OnInit {
  private prevHero = '';
  public heroName = 'Tom';
  public comment = '';

  // …
Run Code Online (Sandbox Code Playgroud)

ngoninit angular

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

如何在ngFor angular 2中使用track

尝试了我能猜出的每一种语法都无法使其有效!

<!--- THIS WORKS FINE --->
<ion-card *ngFor="#post of posts">
{{post|json}}
</ion-card>

<!--- BLANK PAGE --->
<ion-card *ngFor="#post of posts track by post.id">
{{post|json}}
</ion-card>

<!--- Exception : Cannot read property 'id' of undefined --->
<ion-card *ngFor="#post of posts;trackBy:post.id">
{{post|json}}
</ion-card>

<!--- Exception : Cannot read property 'undefined' of undefined --->
<ion-card *ngFor="#post of posts;trackBy:posts[index].id">
{{post|json}}
</ion-card>

<!--- Blank page no exception raised !  --->
<ion-card *ngFor="#post of posts;#index index;trackBy:posts[index].id">
{{post|json}}
</ion-card>
Run Code Online (Sandbox Code Playgroud)

对我有用的唯一方法是

  1. 在控制器类中创建方法

    识别(索引,帖子:帖子){return post.id}

<ion-card *ngFor="#post of …
Run Code Online (Sandbox Code Playgroud)

angularjs-track-by ngfor angular

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

如何在ngFor中使用trackBy

我真的不明白我应该从什么地方回来trackBy.根据我在网上看到的例子,我应该返回对象上某些属性的值.这是对的吗?为什么我将索引作为参数?

例如,在以下情况中:

constructor() {
    window.setInterval(() => this.users = [
            {name: 'user1', score: Math.random()},
            {name: 'user2', score: Math.random()}],
        1000);
}

userByName(index, user) {
    return user.name;
}

...

<div *ngFor="let user of users; trackBy:userByName">{{user.name}} -> {{user.score}}</div>
Run Code Online (Sandbox Code Playgroud)

尽管名称未更改,但模板中显示的对象仍会更新.为什么?

angularjs-track-by ngfor angular

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

Angular2 - ngAfterViewChecked被多次调用..如何在DOM完全加载后调用一次方法?

我需要jqueryAngular2使用时将插件应用于单选按钮Typescript.

如果我指定了ngAfterViewChecked,则会多次调用它,并且控件会多次刷新.

在DOM准备好之后调用javascript方法的替代解决方案是什么?

angular angular-lifecycle-hooks

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

ngOnInit(),ngAfterViewInit(),ngafterContentInit(),ngAfterViewChecked()和构造函数()之间有什么区别?

ngOnInit(),ngAfterViewInit(),ngafterContentInit(),ngAfterViewChecked()和构造函数()之间有什么区别?我们如何在Angular 2中实现它们?他们的目的和用途是什么?实施它们的所有方面都有用吗?

谢谢.

typescript angular angular-lifecycle-hooks

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

在TypeScript中映射通用的spreaded参数类型

我正在尝试编写一个泛型方法,该方法接受任意数量的参数作为对象的键,并使用其键的值作为构造函数的参数.这是我最初的实现:

// Typescript 2.x
export function oldMethod<TProps>() {
  function create<
    TInstance extends Geometry | BufferGeometry,
  >(
    geometryClass: new () => TInstance,
  ): any;
  function create<
    TInstance extends Geometry | BufferGeometry,
    TKey1 extends Extract<keyof TProps, string>,
  >(
    geometryClass: new (param1: TProps[TKey1]) => TInstance,
    key1: TKey1,
  ): any;
  function create<
    TInstance extends Geometry | BufferGeometry,
    TKey1 extends Extract<keyof TProps, string>,
    TKey2 extends Extract<keyof TProps, string>,
  >(
    geometryClass: new (param1: TProps[TKey1], param2: TProps[TKey2]) => TInstance,
    key1: TKey1,
    key2: TKey2,
  ): any;
  function create< …
Run Code Online (Sandbox Code Playgroud)

generic-collections typescript

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

Java:groupingBy subvalue as value

比方说,我有一个对象Person,其字段类型为FirstName和LastName.现在我也有一个List<Person>,我喜欢使用流.

现在我想生成一个Map<FirstName, List<LastName>>以便将具有相同名字的人分组.如何在不编写大量代码的情况下解决这个问题?到目前为止我的方法是

personList
.stream()
.collect(Collectors.groupingBy(
    Person::getFirstName,
    person -> person.getLastName() // this seems to be wrong
));
Run Code Online (Sandbox Code Playgroud)

但似乎这是分配地图价值的错误方法.我应该改变什么?或者我应该使用.reduce new HashMap<FirstName, List<LastName>>()作为初始值,然后通过将元素放入其中来聚合它?

java java-stream collectors

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

如何使用与卡片滑动动画并行创建Android按钮动画

目前我正在使用刷卡库https://github.com/Diolor/Swipecards,我想添加一个带动画的按钮(放大和缩小)与卡的左滑动和右滑动平行.按钮放大缩小应使用刷卡操作进行控制.对此有任何帮助.

java android android-animation android-button

6
推荐指数
0
解决办法
86
查看次数