mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-18 00:59:35 -04:00
Used a weak reference to prevent some memory leaks caused by tasks
This commit is contained in:
parent
0083e6818d
commit
7b93eabefe
@ -5,6 +5,7 @@ import android.content.*;
|
||||
import android.os.*;
|
||||
import android.util.*;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.net.*;
|
||||
import java.text.*;
|
||||
import java.util.*;
|
||||
@ -29,20 +30,20 @@ public class MicrosoftAuthTask extends AsyncTask<String, Void, Object> {
|
||||
*/
|
||||
|
||||
//private Gson gson = new Gson();
|
||||
private RefreshListener listener;
|
||||
private final RefreshListener listener;
|
||||
|
||||
private Context ctx;
|
||||
private final WeakReference<Context> ctx;
|
||||
private ProgressDialog build;
|
||||
|
||||
public MicrosoftAuthTask(Context ctx, RefreshListener listener) {
|
||||
this.ctx = ctx;
|
||||
this.ctx = new WeakReference<>(ctx);
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPreExecute() {
|
||||
build = new ProgressDialog(ctx);
|
||||
build.setMessage(ctx.getString(R.string.global_waiting));
|
||||
build = new ProgressDialog(ctx.get());
|
||||
build.setMessage(ctx.get().getString(R.string.global_waiting));
|
||||
build.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
|
||||
build.setCancelable(false);
|
||||
build.setMax(6);
|
||||
|
@ -4,6 +4,7 @@ import android.content.*;
|
||||
import android.os.*;
|
||||
import net.kdt.pojavlaunch.authenticator.mojang.yggdrasil.*;
|
||||
import java.io.*;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.*;
|
||||
import net.kdt.pojavlaunch.*;
|
||||
import net.kdt.pojavlaunch.value.*;
|
||||
@ -13,11 +14,11 @@ public class InvalidateTokenTask extends AsyncTask<String, Void, Throwable> {
|
||||
//private Gson gson = new Gson();
|
||||
private MinecraftAccount profilePath;
|
||||
|
||||
private Context ctx;
|
||||
private final WeakReference<Context> ctx;
|
||||
private String path;
|
||||
|
||||
public InvalidateTokenTask(Context ctx) {
|
||||
this.ctx = ctx;
|
||||
this.ctx = new WeakReference<>(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -41,7 +42,7 @@ public class InvalidateTokenTask extends AsyncTask<String, Void, Throwable> {
|
||||
@Override
|
||||
public void onPostExecute(Throwable result) {
|
||||
if (result != null) {
|
||||
Tools.showError(ctx, result);
|
||||
Tools.showError(ctx.get(), result);
|
||||
}
|
||||
new File(Tools.DIR_ACCOUNT_NEW + "/" + path + ".json").delete();
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import android.os.*;
|
||||
import com.google.gson.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.*;
|
||||
import net.kdt.pojavlaunch.*;
|
||||
import net.kdt.pojavlaunch.authenticator.mojang.yggdrasil.*;
|
||||
@ -17,18 +18,18 @@ public class RefreshTokenTask extends AsyncTask<String, Void, Throwable> {
|
||||
private RefreshListener listener;
|
||||
private MinecraftAccount profilePath;
|
||||
|
||||
private Context ctx;
|
||||
private final WeakReference<Context> ctx;
|
||||
private ProgressDialog build;
|
||||
|
||||
public RefreshTokenTask(Context ctx, RefreshListener listener) {
|
||||
this.ctx = ctx;
|
||||
this.ctx = new WeakReference<>(ctx);
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPreExecute() {
|
||||
build = new ProgressDialog(ctx);
|
||||
build.setMessage(ctx.getString(R.string.global_waiting));
|
||||
build = new ProgressDialog(ctx.get());
|
||||
build.setMessage(ctx.get().getString(R.string.global_waiting));
|
||||
build.setProgressStyle(ProgressDialog.STYLE_SPINNER);
|
||||
build.setCancelable(false);
|
||||
build.show();
|
||||
|
Loading…
x
Reference in New Issue
Block a user