问题
Based on Android documentation, method onCreateThumbnail is called before pausing the activity, and should draw into outBitmap
the imagery for the desired thumbnail in the dimensions of that bitmap. It can use the given canvas
, which is configured to draw into the bitmap, for rendering if desired.
The default implementation returns fails and does not draw a thumbnail; this will result in the platform creating its own thumbnail if needed.
When the method returns true
, system will not use a standard thumbnail, but custom thumbnail drawn into the canvas
is (or should be) used.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Window window = getWindow();
// cleared by default, but let's make it explicit
window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
}
// @Override
public boolean onCreateThumbnail(Bitmap outBitmap, Canvas canvas) {
Log.d(TAG, "onCreateThumbnail");
return false;
}
However, it seems that the system never call this method. Is there some special settings or flag needed to have this method called and being able to generate own thumbnail for the activity?
回答1:
It is not possible to customize the activity thumbnail which system uses in the recent apps preview.
The method onCreateThumbnail
had been broken since Android 4.0.3, when its call was commented out (see the source code).
来源:https://stackoverflow.com/questions/48853975/android-never-call-method-oncreatethumbnail