吐司消息不服务意图

有没有人有一个想法,为什么以下吐司不出现? 日志被印刷在同一功能的另一土司也正在吐司消息不服务意图

if (searchType.equals("ByName")){ 

// get the extra from the intent:

String query = intent.getStringExtra("query");

if (!searchByName(query)){

Toast.makeText(getApplicationContext(), "No results for this search",

Toast.LENGTH_LONG).show();

Log.d(TAG, "return status true/false -->" + searchByName(query));

}

}

任何帮助将不胜感激

我附加日志,我不得不删除一些行,因为它太长了.. 。 这里是日志:

01-15 10:22:39.267: D/FragmentList(2035): doSearchByName 

01-15 10:22:39.267: D/FragmentList(2035): query -> asdgasdgsdagas

01-15 10:22:39.271: D/FragmentList(2035): ByName

01-15 10:22:39.283: D/FragmentList(2035): currentLocation

01-15 10:22:39.303: D/SearchPlacesSevice(2035): onHandleIntentstart

01-15 10:22:39.303: D/SearchPlacesSevice(2035): ByName

01-15 10:22:39.303: D/SearchPlacesSevice(2035): searchByName

01-15 10:22:39.303: D/GooglePlaces(2035): query -> asdgasdgsdagas

01-15 10:22:39.307: D/GooglePlaces(2035): https://maps.googleapis.com/maps/api/place/textsearch/json?query=asdgasdgsdagas&sensor=false&key=AIzaSyBDi3A3ZLFQPm1I9sUsYasxtwndQjn7mfQ

01-15 10:22:39.879: D/GooglePlaces(2035): {

01-15 10:22:39.879: D/GooglePlaces(2035): "debug_info" : [],

01-15 10:22:39.879: D/GooglePlaces(2035): "html_attributions" : [],

01-15 10:22:39.879: D/GooglePlaces(2035): "results" : [],

01-15 10:22:39.879: D/GooglePlaces(2035): "status" : "ZERO_RESULTS"

01-15 10:22:39.879: D/GooglePlaces(2035): }

01-15 10:22:39.879: D/SearchPlacesSevice(2035): {

01-15 10:22:39.879: D/SearchPlacesSevice(2035): "debug_info" : [],

01-15 10:22:39.879: D/SearchPlacesSevice(2035): "html_attributions" : [],

01-15 10:22:39.879: D/SearchPlacesSevice(2035): "results" : [],

01-15 10:22:39.879: D/SearchPlacesSevice(2035): "status" : "ZERO_RESULTS"

01-15 10:22:39.879: D/SearchPlacesSevice(2035): }

01-15 10:22:39.879: D/SearchPlacesSevice(2035): ZERO_RESULTS

01-15 10:22:39.883: D/SearchPlacesSevice(2035): Status -->ZERO_RESULTS

01-15 10:22:39.887: D/SearchPlacesSevice(2035): searchByName

01-15 10:22:39.887: D/GooglePlaces(2035): query -> asdgasdgsdagas

01-15 10:22:39.887: D/GooglePlaces(2035): https://maps.googleapis.com/maps/api/place/textsearch/json?query=asdgasdgsdagas&sensor=false&key=AIzaSyBDi3A3ZLFQPm1I9sUsYasxtwndQjn7mfQ

01-15 10:22:40.083: D/SearchPlacesSevice(2035): {

01-15 10:22:40.083: D/SearchPlacesSevice(2035): "debug_info" : [],

01-15 10:22:40.083: D/SearchPlacesSevice(2035): "html_attributions" : [],

01-15 10:22:40.083: D/SearchPlacesSevice(2035): "results" : [],

01-15 10:22:40.083: D/SearchPlacesSevice(2035): "status" : "ZERO_RESULTS"

01-15 10:22:40.083: D/SearchPlacesSevice(2035): }

01-15 10:22:40.087: D/SearchPlacesSevice(2035): ZERO_RESULTS

01-15 10:22:40.087: D/SearchPlacesSevice(2035): Status -->ZERO_RESULTS

01-15 10:22:40.091: D/SearchPlacesSevice(2035): return status true/false -->false

01-15 10:22:43.387: W/MessageQueue(2035): Handler (android.os.Handler) {535afd88} sending message to a Handler on a dead thread

01-15 10:22:43.387: W/MessageQueue(2035): java.lang.RuntimeException: Handler (android.os.Handler) {535afd88} sending message to a Handler on a dead thread

01-15 10:22:43.387: W/MessageQueue(2035): at android.os.MessageQueue.enqueueMessage(MessageQueue.java:294)

01-15 10:22:43.387: W/MessageQueue(2035): at android.os.Handler.sendMessageAtTime(Handler.java:473)

01-15 10:22:43.387: W/MessageQueue(2035): at android.os.Handler.sendMessageDelayed(Handler.java:446)

01-15 10:22:43.387: W/MessageQueue(2035): at android.os.Handler.post(Handler.java:263)

01-15 10:22:43.387: W/MessageQueue(2035): at android.widget.Toast$TN.hide(Toast.java:363)

01-15 10:22:43.387: W/MessageQueue(2035): at android.app.ITransientNotification$Stub.onTransact(ITransientNotification.java:55)

01-15 10:22:43.387: W/MessageQueue(2035): at android.os.Binder.execTransact(Binder.java:367)

01-15 10:22:43.387: W/MessageQueue(2035): at dalvik.system.NativeStart.run(Native Method)

01-15 10:23:42.003: D/dalvikvm(2035): GC_CONCURRENT freed 434K, 6% free 8502K/9031K, paused 1ms+1ms, total 8ms

回答:

我认为它在Android框架的错误。每当你尝试制作或显示一个吐司应用程序主线程。 IntentService大部分可能。始终确保您的吐司进入应用程序主线程。

看看下面的解决方法。这一切代码都在您的服务中。

处理程序声明。

Handler handler = null; 

,并在您的服务的构造

handler = new Handler(); 

方法来调用显示吐司。

public void showToast(String message, Context context){ 

handler.post(new CustomToast(message, context));

}

CostomToast

private class CustomToast implements Runnable{ 

String mText;

Context mContext;

public CustomToast(String text, Context context){

mText = text;

mContext = context;

}

public void run(){

Toast.makeText(mContext, mText, Toast.LENGTH_LONG).show();

}

以上是 吐司消息不服务意图 的全部内容, 来源链接: utcz.com/qa/263209.html

回到顶部