English 中文(简体)
如何在守则的结尾采用可变的数值在守则的开头部分加以使用
原标题:How to take a variable s value in the end of the code to use it in the begin of it

我必须把《守则》放在后面,以理解我想要说的话:

public void répondre()
    {
         mt = MediaPlayer.create(context,R.raw.ringtone);
        mt.setVolume(5,5);
      mt.start();
      mt.setLooping(true);
      //startActivity((new Intent(Intent.ACTION_ANSWER)));
        AlertDialog.Builder ad = new AlertDialog.Builder(context);
        ad.setTitle("Appel en cours...");
        ad.setMessage("Voulez vous répondre à cet appel?");
        ad.setPositiveButton("Oui", 
                             new OnClickListener() {
                               public void onClick(DialogInterface dialog, 
                                                   int arg1) {
                                   mt.stop();
                                SipAudioCall incomingCall = null;
                             try {

                                     SipAudioCall.Listener listener = new SipAudioCall.Listener() {
                                        @Override
                                        public void onRinging(SipAudioCall call, SipProfile caller) {
                                            try {

                                                call.answerCall(30);
                                            } catch (Exception e) {
                                                Log.d("Call not answered","Call not answered",e);
                                            }
                                        }

                                    };

                                    SIPCommunicator wtActivity = (SIPCommunicator) context;

                                    incomingCall = wtActivity.manager.takeAudioCall(intent, listener);
                                    incomingCall.answerCall(30);
                                    incomingCall.startAudio();
                                    incomingCall.setSpeakerMode(true);
                                    if(incomingCall.isMuted()) {
                                        incomingCall.toggleMute();
                                    }

                                    wtActivity.call = incomingCall;
                                 String useName = wtActivity.call.getPeerProfile().getDisplayName();
                                    wtActivity.updateStatus("Vous êtes en communication avec " + useName);



                             } catch (Exception e) {
                                if (incomingCall != null) {
                                    incomingCall.close();
                                }
                            }
                        }

                 });

I want to show the caller s name(useName variable) in the AlertDialog. If i put this line(String useName = wtActivity.call.getPeerProfile().getDisplayName();) before MediaPlayerand make ad.setTitle("Appel en cours"+useName); the variable useName is null ! So how doing this ? Thank you very much.

问题回答

幸运的是,我们不需要如问题标题所示,打破因果关系。 打字(这不是处理电话申请的非常常见的情况)是,在你得知即将到来的电话时,打电话的人的名字就没有准备好。 这是因为需要一段时间才能在接触中搜寻打电话者/里。

因此,为了处理这个问题,我建议你做以下工作之一:

  • indicate incoming call via AlertDialog, but present just caller number/URI. Start Handler and second later update the dialog so it displays name.
  • when call arrives, start handler and execute your code just second later. Hopefully at that moment Name will be available.

因此,无论如何,你都需要更新你。 在接到呼吁后,警告会说了一些安全的时间。





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签