0

I want to toast message to display when call is received, it(toast message) has to be there till the call ends, when call ends message has to get disappear.

Any help will be needful

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
  • What do you mean by "when call is received" do you have some code? please elaborate... – Jack Dec 28 '14 at 12:11
  • 2
    A Toast is a **momentary** popup. It's **not persistent**. You need a **Dialog** instead. – Phantômaxx Dec 28 '14 at 12:13
  • A dialog is a small window that prompts the user to make a decision or enter additional information. A dialog does not fill the screen and is normally used for modal events that require users to take an action before they can proceed. – Rateek D'souza Dec 28 '14 at 12:20

3 Answers3

0

Toast doesn't have such functionality. You can give to it custom layout and custom gravity. But nothing more.

When you call show() on it you can't tell it when it should hide. It will be done automatically.

You should use Dialogs.

Anatol
  • 941
  • 1
  • 7
  • 13
  • A dialog is a small window that prompts the user to make a decision or enter additional information. A dialog does not fill the screen and is normally used for modal events that require users to take an action before they can proceed. – Rateek D'souza Dec 28 '14 at 12:22
  • So you want to use `Toast` instead? Sorry, i can't help you here. Now matter how will you name this ui element. You want to have this functionality and the easies way to do this is using dialog. Alternatively you can create some custom view(transparent view) which will you show when the call is received and hide when it ends. – Anatol Dec 28 '14 at 12:30
  • How about this?? toast.setDuration(Toast.LENGHT_LONG); for(int i = 0; i < N; i++) { toast.show(); } @Anatol – Rateek D'souza Dec 29 '14 at 10:22
  • It's a dirty hack. But it will work. You just have to play with numbers, to get a normal effect. Remember that `Toast.LENGTH_LONG` is 3,5 seconds. `private static final int LONG_DELAY = 3500;` And of course you can't garantee that Toast will be ended exactly when the call ends. – Anatol Dec 30 '14 at 07:09
  • Now can you give logic for till ringtone ends till user pick up the call, not ends!! – Rateek D'souza Dec 30 '14 at 07:32
  • @RateekD'souza http://stackoverflow.com/questions/2220560/can-an-android-toast-be-longer-than-toast-length-long. I think you can find this logic yourself. Good luck. – Anatol Dec 30 '14 at 08:58
0

Toast toast = Toast.makeText(context, text, duration); toast.show();

Capten
  • 38
  • 1
  • 4
0

You can't use toasts directly because they can be shown only fixed time which choosed by Toast.LENGTH_LONG or Toast.LENGTH_SHORT, but I see several options here:

  1. Find library such SuperToasts with required functionality.
  2. Create several toasts and show them one after another.

Pseudocode:

    private Handler mHandler = new Handler();

    private void showToasts() {
        Toast.makeText(context, text, duration).show();
        mHandler.postDelayed(new Runnable() {
            public void run() {
                Toast.makeText(context, text, duration).show();
            }
        }, 500);
    }

I'm not sure if it will work, but you can try.

  1. Show your view with PopupWindow, but don't forgeе to handle its lifecircle.
Bracadabra
  • 3,609
  • 3
  • 26
  • 46
  • If he decides to use the SuperToasts library I would recommend using a SuperActivityToast with an indeterminate duration. Then it can be dismissed whenever. – John P. Jan 17 '15 at 05:45
  • It's not neccessary to use SuperActivityToast , because it's used only to handle clicks in toast and orientation changes, – Bracadabra Jan 23 '15 at 14:09