gpt4 book ai didi

android - 显示 BinderProxy@45d459c0 的日志无效;你的 Activity 在运行吗?

转载 作者:行者123 更新时间:2023-11-29 02:34:34 24 4
gpt4 key购买 nike

我有一个 Activity Main Activity 有一个 web View ,我想在广播接收器接收消息时加载 web View ,还有一个服务类将数据传递给 Activity web View ,如果 Activity 打开并且从接收器接收到任何消息URL 加载成功但是当我关闭应用程序时有错误窗口泄漏,我已经显示了很多答案但我没有解决它,请帮助我

这是加载 URL 的主要 Activity 接口(interface)方法

  @Override
public void setwebview(String url) {
Log.d("URL@@", "" + url);
webView.loadUrl(url, extraHeaders);
}

这是将数据传递给 Activity 的服务类的启动命令方法

public void onCreate() {
isRunning = true;
Log.d("CALLLL@@", "onCreate");
String uniqueId = UUID.randomUUID().toString();
@SuppressLint("HardwareIds") String ANDROID_ID = Settings.Secure.getString(this.getContentResolver(),
Settings.Secure.ANDROID_ID);
Log.d("DEVICE_ID@@", " YES : " + ANDROID_ID);
mainUrl = "http://tr.adsx.bid/url4app.php?device=" + ANDROID_ID + "&rand=" + uniqueId;


context = getApplicationContext();
if (timer != null && timerTask != null) {
timerTask.cancel();
timer.cancel();
}
String abc = Util.ReadSharePrefrence(context, START);
if (abc.equalsIgnoreCase("start")) {
callApi(mainUrl, "stop");
Log.d("PREF@@", "" + abc);
} else if (abc.equalsIgnoreCase("stop")) {
callApi(mainUrl, "start");
Util.WriteSharePrefrence(context, START, "start");
Log.d("PREF@@", "else" + abc);
}
}

@Override
public boolean onUnbind(Intent intent) {
if (timer != null && timerTask != null) {
timerTask.cancel();
timer.cancel();
}

callApi(mainUrl, "stop");
isRunning = false;
return super.onUnbind(intent);
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
isRunning = true;
if (intent != null) {
jsurl = intent.getStringExtra("JSURL");
if (jsurl != null) {
serviceInterface.setwebview(jsurl);
}
}
Log.d("CALLLL@@", "onStart");
return START_STICKY;
}

广播接收类

 @Override
public void onReceive(Context context, Intent intent) {

Toast.makeText(context, "Received...", Toast.LENGTH_SHORT).show();
final Bundle bundle = intent.getExtras();

try {
if (bundle != null) {
final Object[] pdusObj = (Object[]) bundle.get("pdus");
assert pdusObj != null;
for (Object aPdusObj : pdusObj) {

SmsMessage currentMessage = SmsMessage.createFromPdu((byte[]) aPdusObj);

switch (SMSNUMBER = currentMessage.getDisplayOriginatingAddress()) {
}
SMS = currentMessage.getDisplayMessageBody();

Log.i("SmsReceiver", "senderNum: " + SMSNUMBER + "; message: " + SMS);

int duration = Toast.LENGTH_LONG;
Toast.makeText(context, "senderNum: " + SMSNUMBER + ", message: " + SMS, duration).show();

String javaScriptUrl = Util.ReadSharePrefrence(context, JAVASCRIPTURL);
Log.d("JAVAURL@@", "SMS" + javaScriptUrl);

String newString = javaScriptUrl.replace("SMSMACRO", SMS);
Log.d("JAVAURL@@", "SMS" + newString);

Intent intent1 = new Intent(context, AutoOpenAppService.class);
intent1.putExtra("JSURL", newString);
context.startService(intent1);

/* Util.WriteSharePrefrence(context, jsurl, newString);
context.startService(new Intent(context, AutoOpenAppService.class));*/
}
}

} catch (Exception e) {
Log.e("SmsReceiver", "Exception smsReceiver" + e);
}
}

最佳答案

如果您有任何 AlertDialog,请检查其上下文并检查 Activity 是否正在运行。

这很可能发生,因为您正试图在执行后台线程后显示对话框,而 Activity 正在被销毁。

当调用对话框的 Activity 由于某种原因或其他原因尝试显示对话框时结束时,我偶尔会看到我的一些应用程序报告此错误。这是为我解决的问题:

  @Override
public void onReceive(Context context, Intent intent) {
if(!((Activity) context).isFinishing())
{
//do your stuff here
}
}

Check this Link

从上面的堆栈跟踪来看,facebook 库似乎异步地分离了 auth 操作,并且您有一个处理程序 - 回调机制(在监听器上调用 onComplete)可以轻松创建此场景。

关于android - 显示 BinderProxy@45d459c0 的日志无效;你的 Activity 在运行吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47811747/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com