即時通訊面臨的一個問題是,即時通過putExtra從電話活動發送線路號碼,並收到撥號活動的值。 getIntent函數第一次收到正確的值,但在第二次時,他無法收到正確的值。第1個谷值第2次出現。意圖功能無法正常工作
手機活動
public class Phone extends Activity
{
List<Map<String, String>> data;
Map<String, String> Line1;
Map<String, String> Line2;
Map<String, String> Line3;
Map<String, String> Line4;
Map<String, String> Line5;
ListView Lines = null;
public void onCreate(final Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
m_objPhone = this;
String sPhoneAccountStatus = VaxStatus.m_objVaxStatus.GetPhoneAccountStatus();
m_objPhoneAccountStatus.setText(sPhoneAccountStatus);
data = new ArrayList<Map<String, String>>();
Line1 = new HashMap<String, String>();
Line1.put("title", "Line | 1");
Line1.put("status", "");
data.add(Line1);
Line2 = new HashMap<String, String>();
Line2.put("title", "Line | 2");
Line2.put("status", "");
data.add(Line2);
Line3 = new HashMap<String, String>();
Line3.put("title", "Line | 3");
Line3.put("status", "");
data.add(Line3);
Line4 = new HashMap<String, String>();
Line4.put("title", "Line | 4");
Line4.put("status", "");
data.add(Line4);
Line5 = new HashMap<String, String>();
Line5.put("title", "Line | 5");
Line5.put("status", "");
data.add(Line5);
SimpleAdapter adapter = new SimpleAdapter(this, data, android.R.layout.simple_list_item_2, new String[] {"title", "status"}, new int[] {android.R.id.text1, android.R.id.text2});
Lines.setAdapter(adapter);
for (int nLineNo = 0; nLineNo < VaxSIPUserAgent.TOTAL_LINE_COUNT; nLineNo++)
{
String sLineStatus = VaxStatus.m_objVaxStatus.GetLineStatus(nLineNo);
SetStatus(nLineNo, sLineStatus);
}
Lines.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3)
{
switch (arg2)
{
case 0:
ShowDialPad(arg2, null);
break;
case 1:
ShowDialPad(arg2, null);
break;
case 2:
ShowDialPad(arg2, null);
break;
case 3:
ShowDialPad(arg2, null);
break;
case 4:
ShowDialPad(arg2, null);
break;
default:
break;
}
}
});
}
@Override
protected void onResume()
{
for (int nLineNo = 0; nLineNo < VaxSIPUserAgent.TOTAL_LINE_COUNT; nLineNo++)
{
String sLineStatus = VaxStatus.m_objVaxStatus.GetLineStatus(nLineNo);
SetStatus(nLineNo, sLineStatus);
}
super.onResume();
}
@Override
protected void onStart()
{
VaxPhone.m_objVaxVoIP.IsMuteMic();
VaxPhone.m_objVaxVoIP.IsMuteSpk();
IncommingCallSlider.m_objCallSlider.SetActiveActivity(this, R.id.PhoneRelativeLayout);
IncommingCallRing.m_objIncommingCallRing.SetActiveActivity(this);
DialCallTone.m_objDialCallTone.SetActiveActivity(this);
super.onStart();
}
@Override
protected void onStop()
{
VaxPhone.m_objVaxVoIP.SetSpeakerState(m_objcheckSpkPhone.isChecked());
super.onStop();
}
@Override
protected void onDestroy()
{
VaxStatus.m_objVaxStatus.SetPhoneActivity(null);
super.onDestroy();
}
public void OnEndCall(int nLineNo)
{
SetStatus(nLineNo, "Ready To Use!");
}
public static void OnContactPhoneNo(String sPhoneNo)
{
int nFreeLineNo = VaxPhone.m_objVaxVoIP.GetFreeLine();
m_objPhone.ShowDialPad(nFreeLineNo, sPhoneNo);
}
public void ShowDialPad(int nFreeLineNo, String sPhoneNo)
{
Intent intent = new Intent(Phone.this , DialPad.class);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
intent.putExtra("LineNo", nFreeLineNo);
intent.putExtra("PhoneNo", sPhoneNo);
startActivity(intent);
}
public void OnStatusPhone(int nLineNo, String sStatusMsg)
{
for (int LineNo = 0; LineNo < VaxSIPUserAgent.TOTAL_LINE_COUNT; LineNo++)
{
String sLineStatus = VaxStatus.m_objVaxStatus.GetLineStatus(LineNo);
SetStatus(LineNo, sLineStatus);
}
if(m_objDialPad != null)
m_objDialPad.OnStatusPhone(sStatusMsg);
}
public void OnStatusAccount(String sStatusMsg)
{
m_objPhoneAccountStatus.setText(sStatusMsg);
if(m_objDialPad != null)
m_objDialPad.OnStatusAccount(sStatusMsg);
}
public void showSelectedNumber(String number)
{
Phone.OnContactPhoneNo(number);
}
void SetStatus(int nLineNo, String sStatusMsg)
{
if(nLineNo == 0)
{
Line1 = new HashMap<String, String>();
Line1.put("title", "Line | 1");
Line1.put("status", sStatusMsg);
data.set(0, Line1);
SimpleAdapter adapter = new SimpleAdapter(this, data, android.R.layout.simple_list_item_2, new String[] {"title", "status"}, new int[] {android.R.id.text1, android.R.id.text2});
Lines.setAdapter(adapter);
}
if(nLineNo == 1)
{
Line2 = new HashMap<String, String>();
Line2.put("title", "Line | 2");
Line2.put("status", sStatusMsg);
data.set(1, Line2);
SimpleAdapter adapter = new SimpleAdapter(this, data, android.R.layout.simple_list_item_2, new String[] {"title", "status"}, new int[] {android.R.id.text1, android.R.id.text2});
Lines.setAdapter(adapter);
}
if(nLineNo == 2)
{
Line3 = new HashMap<String, String>();
Line3.put("title", "Line | 3");
Line3.put("status", sStatusMsg);
data.set(2, Line3);
SimpleAdapter adapter = new SimpleAdapter(this, data, android.R.layout.simple_list_item_2, new String[] {"title", "status"}, new int[] {android.R.id.text1, android.R.id.text2});
Lines.setAdapter(adapter);
}
if(nLineNo == 3)
{
Line4 = new HashMap<String, String>();
Line4.put("title", "Line | 4");
Line4.put("status", sStatusMsg);
data.set(3, Line4);
SimpleAdapter adapter = new SimpleAdapter(this, data, android.R.layout.simple_list_item_2, new String[] {"title", "status"}, new int[] {android.R.id.text1, android.R.id.text2});
Lines.setAdapter(adapter);
}
if(nLineNo == 4)
{
Line5 = new HashMap<String, String>();
Line5.put("title", "Line | 5");
Line5.put("status", sStatusMsg);
data.set(4, Line5);
SimpleAdapter adapter = new SimpleAdapter(this, data, android.R.layout.simple_list_item_2, new String[] {"title", "status"}, new int[] {android.R.id.text1, android.R.id.text2});
Lines.setAdapter(adapter);
}
}
}
撥號活動
public class DialPad extends Activity
{
private TextView m_objStatus;
private Button m_objBtnDial;
int m_nLineNo = -1;
boolean m_objContactFlag;
public static Phone m_objPhone;
private static String[] m_objPhoneNum = new String[VaxSIPUserAgent.TOTAL_LINE_COUNT];
public void onCreate(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
Phone.m_objDialPad = this;
Intent intent = getIntent();
int nIntentExtraLineNo = intent.getIntExtra("LineNo", 1);
m_nLineNo = nIntentExtraLineNo;
final int [] aLineArray = new int[VaxSIPUserAgent.TOTAL_LINE_COUNT - 1];
int nIndex = 0;
for (int nLineNo = 0; nLineNo < VaxSIPUserAgent.TOTAL_LINE_COUNT; nLineNo++)
{
if(m_nLineNo == nLineNo)
continue;
aLineArray[nIndex] = nLineNo + 1;
nIndex++;
}
String sLineStatus = VaxStatus.m_objVaxStatus.GetLineStatus(m_nLineNo);
OnStatusPhone(sLineStatus);
String sPhoneNo = intent.getStringExtra("PhoneNo");
if(sPhoneNo != null)
{
m_objPhoneNum[nIntentExtraLineNo] = sPhoneNo;
}
m_objEditDialscreen.setText(m_objPhoneNum[nIntentExtraLineNo]);
}
@Override
protected void onStart()
{
UpdateDialBtn();
if(m_objContactFlag == false)
m_objEditDialscreen.setText(m_objPhoneNum[m_nLineNo]);
IncommingCallSlider.m_objCallSlider.SetActiveActivity(this, R.id.dialpad);
IncommingCallRing.m_objIncommingCallRing.SetActiveActivity(this);
DialCallTone.m_objDialCallTone.SetActiveActivity(this);
super.onStart();
}
@Override
protected void onStop()
{
m_objPhoneNum[m_nLineNo] = m_objEditDialscreen.getText().toString();
super.onStop();
}
}
這是'Phone.java'類的所有代碼嗎? –
檢查你是否在第二次傳遞相同的'sPhoneNo和nFreeLineNo' – SathishKumar
你是否在AndroidManifest的DialPad Activity中有任何標誌,如SINGLE_TOP或smth else。如果是這樣的創建可能不會被調用。在這種情況下,您必須重寫activity中的onNewIntent()方法。 –