我RecyclerView
在教授的申请中使用的是查看学生名单的位置,其中将包含照片和其他详细信息以及删除选项。我试图仔细做的所有事情。但是存在一个问题,即来自Firebase的照片无法加载到RecyclerView
。有时它会加载一两张照片,然后停止加载照片。我正在加载应用程序时观察android
Studio上的“运行”选项。然后我发现类似…
W/art: Throwing OutOfMemoryError "Failed to allocate a 71663628 byte allocation with 4188416 free bytes and 46MB until OOM"
V/FA: Inactivity, disconnecting from the service
为什么这个问题发生在我身上,我真的还没有。拜托,帮我摆脱这个问题。
在寻找了很多东西之后,我尝试了一些步骤,以使缓存无效/重启。但这对我没有用。
这是我的主要活动RecyclerView
:
public class HRequestedStudents extends AppCompatActivity {
DatabaseReference databaseReference;
ProgressDialog progressDialog;
List<RegisteredStudent> list = new ArrayList<>();
RecyclerView recyclerView;
RecyclerView.Adapter adapter ;
RequestedStudents madapter;
RegisteredStudent registeredStudent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hrequested_students);
recyclerView = (RecyclerView) findViewById(R.id.recycleView);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(HRequestedStudents.this));
progressDialog = new ProgressDialog(HRequestedStudents.this);
progressDialog.setMessage("Loading Data...");
progressDialog.show();
databaseReference = FirebaseDatabase.getInstance().getReference("RegisteredStudent");
databaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
list.clear();
for (DataSnapshot dataSnapshot : snapshot.getChildren()) {
registeredStudent = dataSnapshot.getValue(RegisteredStudent.class);
list.add(registeredStudent);
}
adapter = new RequestedStudents(HRequestedStudents.this, list);
recyclerView.setAdapter(adapter);
progressDialog.dismiss();
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
progressDialog.dismiss();
}
});
}
}
这是我的适配器活动
public class RequestedStudents extends RecyclerView.Adapter<RequestedStudents.RecyclerViewHolder> {
private Context mContext;
ProgressDialog progressDialog;
List<RegisteredStudent> requestedStudents;
FirebaseStorage mFirebaseStorage = getInstance();
DatabaseReference mRef = FirebaseDatabase.getInstance().getReference("RegisteredStudent");
public RequestedStudents(Context context, List<RegisteredStudent> list) {
mContext=context;
requestedStudents = list;
}
@Override
public RecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(mContext).inflate(R.layout.hrstudentlistitems, parent, false);
return new RecyclerViewHolder(view);
}
@Override
public void onBindViewHolder(RecyclerViewHolder holder, int position) {
RegisteredStudent currentStudentDetails = requestedStudents.get(position);
holder.name.setText("Name: "+currentStudentDetails.getRegeName());
holder.room.setText("Room: "+currentStudentDetails.getRegeRoom());
holder.id.setText("ID: "+currentStudentDetails.getRegeID());
holder.batch.setText("Batch: "+currentStudentDetails.getRegeBatch());
holder.dept.setText("Department: "+currentStudentDetails.getRegeDept());
holder.email = currentStudentDetails.getRegeEmail();
holder.nam = currentStudentDetails.getRegeName();
holder.rum = currentStudentDetails.getRegeRoom();
holder.mobile = currentStudentDetails.getRegeMobile();
holder.pass = currentStudentDetails.getRegePass();
holder.iD = currentStudentDetails.getRegeID();
holder.Batch = currentStudentDetails.getRegeID();
holder.Dept = currentStudentDetails.getRegeDept();
holder.imageUri = currentStudentDetails.getImageUri();
Picasso.get().load(currentStudentDetails.getImageUri()).into(holder.profile_photo);
}
@Override
public int getItemCount() {
return requestedStudents.size();
}
public class RecyclerViewHolder extends RecyclerView.ViewHolder {
public TextView name, id, room, batch, dept;
public String email, mobile, imageUri, pass, iD, nam, rum, uId, Batch, Dept;
public CircleImageView profile_photo;
public Button remove, accept;
public RecyclerViewHolder(View item) {
super(item);
name = item.findViewById(R.id.name);
room = item.findViewById(R.id.room);
id = item.findViewById(R.id.id);
batch = item.findViewById(R.id.batch);
dept = item.findViewById(R.id.dept);
profile_photo = item.findViewById(R.id.profile_photo);
remove = item.findViewById(R.id.remove);
accept = item.findViewById(R.id.accept);
item.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
progressDialog = new ProgressDialog(mContext);
progressDialog.setMessage("Please Wait...");
progressDialog.show();
LayoutInflater inflater = LayoutInflater.from(mContext);
View view = inflater.inflate(R.layout.student_bistarito, null);
CircleImageView imagebi = view.findViewById(R.id.imagebi);
TextView nambi = view.findViewById(R.id.nambi);
TextView rumbi = view.findViewById(R.id.rumbi);
Button call = view.findViewById(R.id.call);
Button cancel = view.findViewById(R.id.cancel);
final AlertDialog alertDialog = new AlertDialog.Builder(mContext).create();
nambi.setText("Name: " + nam);
rumbi.setText("Room: " + rum);
Picasso.get().load(imageUri).into(imagebi);
progressDialog.dismiss();
uId = FirebaseAuth.getInstance().getUid();
call.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(Intent.ACTION_CALL);
i.setData(Uri.parse("tel:" + mobile));
if (ContextCompat.checkSelfPermission(mContext, CALL_PHONE) == PackageManager.PERMISSION_GRANTED) {
mContext.startActivity(i);
} else {
Toast.makeText(mContext, "Go to settings and allow call permission", Toast.LENGTH_LONG).show();
}
alertDialog.dismiss();
}
});
cancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
Toast.makeText(mContext, "Shubho", Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Toast.makeText(mContext, e.getMessage(), Toast.LENGTH_LONG).show();
}
alertDialog.dismiss();
}
});
alertDialog.setView(view);
alertDialog.show();
alertDialog.getWindow().setBackgroundDrawable(null);
}
});
profile_photo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
LayoutInflater inflater = LayoutInflater.from(mContext);
View vi = inflater.inflate(R.layout.activity_photo, null);
ImageView photo = vi.findViewById(R.id.image);
Button close = vi.findViewById(R.id.close);
final AlertDialog ad = new AlertDialog.Builder(mContext).create();
Picasso.get().load(imageUri).into(photo);
close.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ad.dismiss();
}
});
ad.setView(vi);
ad.show();
ad.getWindow().setBackgroundDrawable(null);
}
});
accept.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
remove.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
builder.setTitle("Delete");
builder.setMessage("Are you sure to remove this student?");
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
try {
Query query = mRef.orderByChild("email").equalTo(email);
query.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot ds : dataSnapshot.getChildren()) {
ds.getRef().removeValue();
}
Toast.makeText(mContext, "Removed Successfully!", Toast.LENGTH_SHORT).show();
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
Toast.makeText(mContext, databaseError.getMessage(), Toast.LENGTH_SHORT).show();
}
});
StorageReference mPictureReferance = getInstance().getReferenceFromUrl(imageUri);
mPictureReferance.delete().addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Toast.makeText(mContext, "Removed Successfully!", Toast.LENGTH_SHORT).show();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(mContext, e.getMessage(), Toast.LENGTH_SHORT).show();
}
});
} catch (Exception e) {
Toast.makeText(mContext, e.getMessage(), Toast.LENGTH_LONG).show();
}
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.create().show();
}
});
}
}
}
我想将所有图像加载到中,RecyclerView
而不会出现错误行“不活动,正在与服务断开连接”。我该如何解决?
我能想到的最好的解决方案是使用Resize Images
Extension
:
将上传到Cloud Storage的图像调整为指定大小,并存储原始图像和调整后的图像。
这是Github 仓库。
问题内容: 我正在尝试将调整大小的图像上传到S3: 但我得到一个错误: 问题答案: 您需要先将输出图像转换为一组字节,然后才能上载到s3。您可以将图像写入文件然后上传文件,也可以使用cStringIO对象来避免写入磁盘,就像我在这里所做的那样:
问题内容: 我一直在搜索google,只遇到过降低高度/宽度或通过CoreImage如何编辑UIImage外观的库。但是我还没有看到或找到一个库,这篇文章解释了如何减小图像大小,因此在上载时,它不是完整的图像大小。 到目前为止,我有这个: 并且正在发送12MB的照片。如何将其减小到1mb?谢谢! 问题答案: Xcode 9•Swift 4或更高版本 编辑/更新:对于iOS10 +,我们可以使用UI
问题内容: 在Java中,如何将图像的大小调整为任何类型或大小的默认大小? 问题答案: 网上有很多关于如何执行此操作的文章,类似的内容应该可以帮助您: 最终的Java图像处理(包括 许多 其他图像功能)
问题内容: 所以我想做的是从网址中流式传输图像,用graphicsmagick处理并将其流式传输到s3。我只是不工作。 将处理后的图像流式传输到本地磁盘(使用fs.createWriteStream)可以正常工作。 当我缓冲流时,s3中的最终图像至少具有预期的大小(以kb为单位),但是我无法打开该图像。 那就是我当前的进度: 我确实尝试了一些诸如创建filewritestream和fileread
以下是我现在使用HTML5文件API上传多个图像的代码片段: 我想在使用canvas对象上传之前调整图像大小,但没有这方面的经验,我不确定如何使用技术更新代码,例如这里描述的技术:HTML5在上传之前预调整图像大小 将返回一个编码字符串。但是我需要发布对象。 您将如何(合理地)为大多数现代浏览器编写跨浏览器功能,以便在上传之前调整文件大小,以透明方式处理jpg、png和GIF:
问题内容: 我在这里使用Go调整大小包:https://github.com/nfnt/resize 我正在从S3中提取图像,如下所示: // this gives me data []byte 之后,我需要调整图像大小: // problem is that the original_image has to be of type image.Image 将图像上传到我的S3存储桶 // pro