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