диалог оповещения занимает слишком много времени, и я не понимаю, почему это происходит. когда я нажимаю на любой элемент в диалоговом окне с предупреждением, мое приложение останавливается и реагирует через несколько секунд. Диалоговое окно оповещения не исчезает быстро. URL изображений взят из базы данных Firebase. Я кодирую в API 28
setwallpaper - это действие только с одним просмотром изображения
setwallpaper. java
public class setwallpaper extends AppCompatActivity{
private static final int PERMISSION_REQUEST_CODE =1000 ;
// DrawerLayout drawer;
//Button btn_set,btn_download;
ImageView imageView_set;
int index;
ProgressBar progressBar;
AlertDialog.Builder builder;
//WeakReference<ContentResolver> contentResolverWeakReference ;
//ProgressDialog mProgressDialog;
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
// contentResolverWeakReference = new WeakReference<ContentResolver>(getApplicationContext().getContentResolver());
switch (requestCode){
case PERMISSION_REQUEST_CODE:
{
if (grantResults.length>0&&grantResults[0]==PackageManager.PERMISSION_GRANTED){
Toast.makeText(this, "permission granted", Toast.LENGTH_SHORT).show();
}else {
Toast.makeText(this, "permission denied", Toast.LENGTH_SHORT).show();
}
}
break;
}
}
@RequiresApi(api = Build.VERSION_CODES.M)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_setwallpaper);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)!= PackageManager.PERMISSION_GRANTED){
requestPermissions(new String[]{
Manifest.permission.WRITE_EXTERNAL_STORAGE
},PERMISSION_REQUEST_CODE);
}
// Toolbar toolbar = findViewById(R.id.toolbar);
//setSupportActionBar(toolbar);
//final NavigationView navigationView=findViewById(R.id.nav_view);
//navigationView.setNavigationItemSelectedListener(this);
progressBar=findViewById(R.id.progressBar);
progressBar.setVisibility(View.GONE);
imageView_set=findViewById(R.id.imageview_set);
Intent intent=new Intent();
//String url=intent.getStringExtra("url");
int postion=getIntent().getIntExtra("url",0);
index=postion;
Picasso.get().load(array_class.arrayurl.get(postion).getImage()).into(imageView_set);
imageView_set.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// WallpaperManager wallpaperManager = WallpaperManager.getInstance(setwallpaper.this);
builder = new AlertDialog.Builder(setwallpaper.this);
builder.setTitle("Title");
builder.setItems(new CharSequence[]
{"set homescreen", "set lockscreen", "download"},
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// The 'which' argument contains the index position
// of the selected item
switch (which) {
case 0:
setimage();
//Toast.makeText(setwallpaper.this, "hello", Toast.LENGTH_SHORT).show();
break;
case 1:
setlockimage();
Toast.makeText(setwallpaper.this, "hello", Toast.LENGTH_SHORT).show();
break;
case 2:
if (ActivityCompat.checkSelfPermission(setwallpaper.this, Manifest.permission.WRITE_EXTERNAL_STORAGE)!= PackageManager.PERMISSION_GRANTED){
Toast.makeText(setwallpaper.this, "you should grant permission", Toast.LENGTH_SHORT).show();
requestPermissions(new String[]{
Manifest.permission.WRITE_EXTERNAL_STORAGE
},PERMISSION_REQUEST_CODE);
return;
}else {
final String filename= UUID.randomUUID().toString()+".jpg";
Picasso.get().load(array_class.arrayurl.get(index).getImage()).into(new settingimagehelper(setwallpaper.this,
getApplicationContext().getContentResolver()
,filename,"image desc"));
}
Toast.makeText(setwallpaper.this, "downloaded", Toast.LENGTH_SHORT).show();
break;
}
}
});
builder.create().show();
}
});
setResult(RESULT_OK);
}
private void setimage() {
Picasso.get()
.load(array_class.arrayurl.get(index).getImage())
.into(new Target() {
@Override
public void onBitmapLoaded (final Bitmap bitmap, Picasso.LoadedFrom from){
/* Save the bitmap or do something with it here */
progressBar.setVisibility(View.VISIBLE);
//Set it in the ImageView
WallpaperManager wallpaperManager = WallpaperManager.getInstance(setwallpaper.this);
try {
wallpaperManager.setBitmap(bitmap);
progressBar.setVisibility(View.GONE);
Toast.makeText(setwallpaper.this, "wallpaper set as background", Toast.LENGTH_SHORT).show();
} catch (IOException ex) {
ex.printStackTrace();
}
}
@Override
public void onBitmapFailed(Exception e, Drawable errorDrawable) {
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
progressBar.setVisibility(View.VISIBLE);
}
});
}