我试图从记忆中清除一些观点.
这是情况.我有一个活动,我称之为A和另一个B.
现在我按下活动A中的一个按钮,调用活动B,动态创建大量视图.之后,我按回按钮返回活动A重复这两个步骤很多次.
结果是,在DDMS中,对象和内存的数量分配的静止图像增长(对象数量增加了88,分配了0,002MB)这意味着视图不会从内存中删除!
如何从内存中完全清除视图?
谢谢 !
更新 - 在这里您可以获得一些新信息
基本上,在我的"真实世界"中,我只有很多次创建的Activity.发生这种情况是因为我必须与Web服务进行通信,并且所有响应都是在此活动的新实例中创建的.
我尝试使用下面的代码解决此问题
@Override
protected void onDestroy() {
super.onDestroy();
nullViewDrawablesRecursive(mRootView);
mRootView = null;
System.gc();
}
Run Code Online (Sandbox Code Playgroud)
那是我的nullViewDrawablesRecursive
private void nullViewDrawablesRecursive(View view) {
if (view != null) {
try {
ViewGroup viewGroup = (ViewGroup) view;
int childCount = viewGroup.getChildCount();
for (int index = 0; index < childCount; index++) {
View child = viewGroup.getChildAt(index);
nullViewDrawablesRecursive(child);
}
} catch (Exception e) {
}
nullViewDrawable(view);
}
}
Run Code Online (Sandbox Code Playgroud)
那是我的nullViewDrawable
private void nullViewDrawable(View view) {
try {
view.setBackgroundDrawable(null); …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个行为类似于tools:context的自定义属性,即
这是我的resources.xml
<declare-styleable name="RecyclerView">
<attr name="adapter" format="string"></attr>
</declare-styleable>
Run Code Online (Sandbox Code Playgroud)
这是用法
<example.com.br.appname.RecyclerView
android:id="@+id/accounts"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="8dp"
app:adapter="example.com.br.appname.AccountAdapter" >
</example.com.br.appname.RecyclerView>
Run Code Online (Sandbox Code Playgroud)
我试过使用格式参考,但它也没有编译。
错误:(17, 22) 不允许字符串类型(在“适配器”处,值为“example.com.br.appname.AccountAdapter”)。
有没有办法从 WorkManager Google API测试PERIODIC工作人员,而无需为每次执行至少等待 15 分钟?
我的意思是,它是一个调试应用程序,我正在通过 Android Studio 运行它,我不想等待这么长时间来测试我的功能。
我正在尝试使用Android Camera API但是当我拍照时,它的分辨率与我的Camera对象previewSize分辨率相同.
一些代码解释:
private Camera mCamera;
private Camera.PictureCallback mPictureCallback;
...
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
...
Camera.Parameters p = mCamera.getParameters();
p.setPreviewSize(mPreviewWidth, mPreviewHeight);
p.setPictureSize(mPictureWidth,mPictureHeight);
mCamera.setParameters(p);
...
}
public void onPictureTaken(byte[] imageData, Camera c) {
Bitmap bitmapPicture = BitmapFactory.decodeByteArray(imageData, 0, imageData.length);
bitmapPicture.getWidth(); //At this point the width is the same as mPreviewWidth and I want it to be mPictureWidth
}
/**
* This function is called when the user touches the surfaceview
*/
public void …Run Code Online (Sandbox Code Playgroud)