我通过以下代码在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
如果我希望每次加载组件时都会发生函数x,无论是第一次加载,我都会导航到另一个站点并导航回来,或者是组件第五次加载.
我应该把函数x放入什么?组件构造函数还是OnInit?
我无法理解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) 尝试了我能猜出的每一种语法都无法使其有效!
<!--- 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)
对我有用的唯一方法是
在控制器类中创建方法
识别(索引,帖子:帖子){return post.id}
和
<ion-card *ngFor="#post of …Run Code Online (Sandbox Code Playgroud) 我真的不明白我应该从什么地方回来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)
尽管名称未更改,但模板中显示的对象仍会更新.为什么?
我需要jquery在Angular2使用时将插件应用于单选按钮Typescript.
如果我指定了ngAfterViewChecked,则会多次调用它,并且控件会多次刷新.
在DOM准备好之后调用javascript方法的替代解决方案是什么?
ngOnInit(),ngAfterViewInit(),ngafterContentInit(),ngAfterViewChecked()和构造函数()之间有什么区别?我们如何在Angular 2中实现它们?他们的目的和用途是什么?实施它们的所有方面都有用吗?
谢谢.
我正在尝试编写一个泛型方法,该方法接受任意数量的参数作为对象的键,并使用其键的值作为构造函数的参数.这是我最初的实现:
// 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) 比方说,我有一个对象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>>()作为初始值,然后通过将元素放入其中来聚合它?
目前我正在使用刷卡库https://github.com/Diolor/Swipecards,我想添加一个带动画的按钮(放大和缩小)与卡的左滑动和右滑动平行.按钮放大缩小应使用刷卡操作进行控制.对此有任何帮助.
angular ×6
android ×2
java ×2
ngfor ×2
ngoninit ×2
typescript ×2
collectors ×1
constructor ×1
java-stream ×1