我是第一次制作Android应用程序,我遇到了这个问题.当用户A向另一个用户B发送好友请求时,用户B获得通知.我希望当用户B点击通知时重定向到用户A配置文件.
主要活动(应用程序中的主页)根据用户来自何处打开不同的片段.用户简档就是这样一个片段.
这就是我从主活动的演示者类发送通知的方式.
Intent notificationIntent = new Intent(activity.getApplicationContext(), MainActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
Bundle extras = new Bundle();
extras.putString("name" ,this.friendRequestFromUserName.toString());
extras.putString("email", this.friendRequestFromUserEmail);
extras.putString("notification", "notificationFriendRequest");
notificationIntent.putExtras(extras);
System.out.println("PUTTING EXTRA");
System.out.println(notificationIntent.getExtras().toString());
// output here is:
//Bundle[{name=The Lion King, email=mufasa@lionking.com, notification=notificationFriendRequest}]
NotificationCompat.Builder builder = new NotificationCompat.Builder(activity)
.setSmallIcon(R.drawable.ic_notification)
.setContentTitle("New friend!")
.setContentText(this.friendRequestFromUserName + " wants to be friends.")
.setAutoCancel(true)
.setOnlyAlertOnce(true)
.setOngoing(false)
.setContentIntent(PendingIntent.getActivity(activity.getApplicationContext(), 0, notificationIntent, 0));
builder.setOngoing(false);
builder.setAutoCancel(true);
Notification not = builder.build();
not.flags = Notification.FLAG_AUTO_CANCEL;
NotificationManager manager = (NotificationManager)this.activity.getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(123, not);
Run Code Online (Sandbox Code Playgroud)
但是在主要活动中,当用户点击通知时,只有部分Bundle是"到达".以下是我尝试获取额外内容的方法:
extraName = intent.getStringExtra("name");
extraMail = intent.getStringExtra("email");
extra = …Run Code Online (Sandbox Code Playgroud) android extras android-intent android-fragments android-pendingintent
我重载了下标运算符和赋值运算符,我试图Array x;
x[0]=5;
通过重载下标运算符来获得赋值运算符示例的正确值,
我可以获得值 0,但是当我重载赋值运算符时,它会进行赋值,但它不使用我的重载函数,因为可用2 的值应该是 5。
class Array
{
public:
int *ptr;
int one,two;
Array(int arr[])
{
ptr=arr;
}
int &operator[](int index)
{
one=index;
return ptr[index];
}
int & operator=(int x){
two=x;
return x;
}
};
int main(void)
{
int y[]={1,2,3,4};
Array x(y);
x[1]=5;
cout<<x[0]<<endl;
}
Run Code Online (Sandbox Code Playgroud) c++ overloading operator-overloading subscript assignment-operator
我有 2 个实体,我想在它们之间创建一个关系,以便它们共享它们的主键。当我们提交一个实体时,另一个实体也应该使用为第一个实体生成的相同主键提交。
我的第一个实体是用户
@Entity
@Table(name = "ENDUSER")
public class User extends LongIdBase implements IActivatable, IUser {
@Column(name = "first_name")
private String firstName;
@Column(name = "last_name")
private String lastName;
@OneToOne(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, targetEntity = UserLoginRecord.class)
@PrimaryKeyJoinColumn(name = "id")
private UserLoginRecord userLoginRecord;
Run Code Online (Sandbox Code Playgroud)
我的第二个实体是 UserLoginrecord
@Entity
@Table(name = "ENDUSER_TEMP")
public class UserLoginRecord {
@Id
@Column(name = "id")
private Long id;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Column(name …Run Code Online (Sandbox Code Playgroud)