I have an android PrintService launched by an Application.
I would like to be able to display toasts from the PrintService when I'm selecting the printer on which to print etc. (UI generated by the android system, picture here).
On Android <11 it works fine, however for 11+, I'm not able to display a toast...
I've tried several code (Kotlin) :
Toast.makeText(<context>, message, Toast.LENGTH_LONG).show()
Handler(Looper.getMainLooper()).post {
Toast.makeText(context.applicationContext, message, Toast.LENGTH_LONG).show()
}
Where I tried the following values of :
this (the PrintService)
this.applicationContext
this.baseContext
Still, I'm never able to display a toast on the printer selection page...
Is it possible ? What is wrong in my code ?
I am currently new to Android programming and I am trying to test parts of UI using espresso. Currently, I have a problem with a testing toast message.
Toast toast = Toast.makeText(context, R.string.some_message, duration);
toast.show();
And then in my test file, I define the Activity Scenario Rule.
public ActivityScenarioRule<CreateActivity> activityScenarioRule =
new ActivityScenarioRule<>(SomeActivity.class);
At the end the best solution that I get for testing this part looks like this.
ActivityScenario<SomeActivity> scenario = activityScenarioRule.getScenario();
scenario.onActivity(activity ->
Espresso.onView(ViewMatchers.withText(R.string.error_message)).inRoot(RootMatchers.withDecorView
(not(is(activity.getWindow().getDecorView())))).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
);
When I run the test it never stops. Any help would be useful. :)
I want to check the alert message text at login time if someone enters wrong credential then alert message will show.In my test cases i have check the alert message if its wrong or right.But somehow,if the text in test cases will be "Invali Email" and alert show "Invalid email id" then the app should not stop testing another cases.What i meant is it should resume or something do,which do not effect further cases
if(!emailValidator(editText.getText().toString())){
buttonlogin.click();
UiObject notice_message = new UiObject(new UiSelector().resourceId("com.vastedge.priceguide:id/notcicemesage"));
assertEquals("Invalid email",notice_message.getText().toString());
onView(withId(R.id.ok)).perform(click());
}
I show the toast, it doesn't disappear, even after the app is closed. How do I fix?
#Override
public void onClipStoreLoadedClipsNotification(ClipStoreLoadedClipsNotification notif)
{
final ClipStoreLoadedClipsNotification notification = notif;
runOnUiThread(new Runnable() {
#Override
public void run()
{
Dialogs.DismissAll();
list.onRefreshComplete();
TextView text = (TextView)findViewById(R.id.loadclipstext);
ProgressBar pb = (ProgressBar)findViewById(R.id.loadclipsprogress);
if (notification.moreClipsAvailable)
{
text.setText(context.getString(R.string.loading_clips));
pb.setVisibility(View.VISIBLE);
}
else
{
text.setText(context.getString(R.string.no_clips));
pb.setVisibility(View.INVISIBLE);
int duration = Toast.LENGTH_SHORT;
Toast.makeText(SugarLoafContext.playbackTabContext, "No clips found.", duration).show();
}
SugarLoafContext.currentCamera = notification.camera;
clipList = notification.clips;
refreshListView();
readyToLoadMoreClips = true;
if (!firstClipsLoaded)
firstClipsLoaded = true;
}
});
}
Is it running inside a IntentService???
If it is so, the problem is that the Intent Services in Android run in a different thread than the main one, so the Toast is shown in a different thread than the main one, after the time to show is finished, the Android system is unable to find where is the Toast, so it can´t remove it.
I had the same problem, and now, i recommend everyone NOT to show Toast inside a IntentService, instead try to run one commom Service, or to open an Activity, or try something different if it is completely necessary to show the Toast.
The fact that the Toast doesn´t dissapear when you close the App is that the IntentService is still running, and you have to reboot the system or to uninstall the App for the Intent Service to be close.
The only explanation is that your Toast is called in a loop. You should track the toast .show() and see if it is not called an infinite times.
An other visual way would be to do this
Toast.makeText(SugarLoafContext.playbackTabContext, "No clips found.", duration).show();
Toast.makeText(SugarLoafContext.playbackTabContext, "Do you understand now?", duration).show();
I am sure you will see both toast alternatively during a looong time...
This can also happen if your device has no network connection, and your app does a license check and shows a Toast of results. One of my apps had this problem, as I was displaying a Toast when checking the app was licensed. Without a network connection the Toast telling the user that a license retry was to be done remained, and when I connected the Toast was removed, because the license check could work.
I want to show Error(log) messages from catch block. How can I show all messages(stack) on a single Screen, so that user can get an idea ?
Thanks...
How about using Toast?
Sample:
Toast.makeText(getBaseContext(), getResources().getString(resourceIDForMessage), Toast.LENGTH_SHORT).show();