我试图通过广播接收器将一个实现“可序列化”的对象从一个应用程序发送到另一个应用程序。
我想发送一个类,如:
public class MyObject implements Serializable{
//basic properties
}
Run Code Online (Sandbox Code Playgroud)
在应用程序 A 中,我这样做:
Intent i = new Intent("myApplication.string");
Bundle b = new Bundle();
b.putSerializable("myclass",obj);
i.putExtras(b);
sendBroadcast(i);
Run Code Online (Sandbox Code Playgroud)
当我调试这个时,我可以验证对象是否正确存储在意图中的包中。
在应用程序 B 中,我这样做:
显现
<receiver
android:name="com.example.myapplication.myreceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="myApplication.string"/>
</intent-filter>
</receiver>
Run Code Online (Sandbox Code Playgroud)
广播接收器
@Override
public void onReceive(Context context, Intent intent) {
try{
Bundle b = intent.getExtras();
MyObject s = (MyObject)b.getSerializable("myclass");
}catch (Exception e){
Log.d(TAG,e.getMessage());
}
}
Run Code Online (Sandbox Code Playgroud)
在应用程序 B 中,意图不保存它在应用程序 A 中所做的数据。
当我尝试投射数据时,它会抛出:
Parcelable encountered ClassNotFoundException reading a Serializable object (name = com.example.myApplication.MyObject) …
Run Code Online (Sandbox Code Playgroud) 所以,我已经完成了使用IB
in Xcode
并希望UI
在Swift中编写所有内容.
所以我做的是:
UIView
的包含我想写的元素 - 让我们称之为"TestView"TestView
到a VC
作为子视图.在TestView
课堂上我添加了这样的元素:
class TestView: UIView {
var someLabel:UILabel!
override init(frame: CGRect) {
super.init(frame: frame)
self.someLabel = UILabel(frame: CGRect(x: self.frame.midX, y: oneSixthHeight, width: 100, height: 22))
self.someLabel.text = "test"
var constraints:[NSLayoutConstraint] = []
self.someLabel.translatesAutoresizingMaskIntoConstraints = false
let rightsideAnchor:NSLayoutConstraint = NSLayoutConstraint(item: self.someLabel, attribute: .Trailing, relatedBy: .Equal, toItem: self, attribute: .Trailing, multiplier: 1, constant: 1)
constraints.append(rightsideAnchor)
NSLayoutConstraint.activateConstraints(constraints)
}
}
Run Code Online (Sandbox Code Playgroud)有了这个,我希望将UILabel
它固定在视图的右侧.
但是,我确实收到此错误:
由于未捕获的异常'NSGenericException'而终止应用程序,原因:'无法激活带有项的约束>和>因为它们没有共同的祖先. …
我试图通过webapi后面的aspnetcore.identity UserManager删除用户。
[HttpPost("Delete", Name = "DeleteRoute")]
[Authorize(Roles = "SuperUser")]
public async Task<IActionResult> DeleteAsync([FromBody] User user)
{
Console.WriteLine("Deleting user: " + user.Id);
try {
await _userManager.DeleteAsync(user);
return Ok();
} catch(Exception e) {
return BadRequest(e.Message);
}
}
Run Code Online (Sandbox Code Playgroud)
这引发了 DbUpdateConcurrencyException
Microsoft.EntityFrameworkCore.DbUpdateConcurrencyException: Database operation expected to affect 1 row(s) but actually affected 0 row(s). Data may have been modified or deleted since entities were loaded. See http://go.microsoft.com/fwlink/?LinkId=527962 for information on understanding and handling optimistic concurrency exceptions.
at Microsoft.EntityFrameworkCore.Update.AffectedCountModificationCommandBatch.ThrowAggregateUpdateConcurrencyException(Int32 commandIndex, Int32 expectedRowsAffected, Int32 rowsAffected)
at …
Run Code Online (Sandbox Code Playgroud)