ActivityManager: Warning: Activity not started, it

Java Code:

package com.example.phone5; import android.app.Activity; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button callBT = (Button) findViewById(R.id.callBT); callBT.setOnClickListener(new MyOnClickListener()); } public class MyOnClickListener implements OnClickListener { public void onClick(View v) { // 找到文本框 EditText GetNum = (EditText) findViewById(R.id.GetNum); // 從文本框裏面獲取號碼 String num = GetNum.getText().toString(); // 建立意圖對象 Intent intent = new Intent(); // 設定打電話這個動做 intent.setAction(Intent.ACTION_CALL); // 設定獲取電話號碼 intent.setData(Uri.parse("tel:" + num)); startActivity(intent); } } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }






XML Code

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/Number" />

    <EditText
        android:id="@+id/GetNum"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

    <Button
        android:id="@+id/callBT"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/call" />

</LinearLayout>



在編寫一個Phone Application程序的時候出現了一個問題:console顯示,ActivityManager: Warning: Activity not started, its current task has been brought to the front java

解決思路:百度(有了問題本身分析考慮事後沒找到思路問百度) 也就是在修改了代碼後,在沒有從新編譯這步, 模擬器原來的.apk就不會通過卸載跟從新安裝這一步;因此當在eclipse中只是點擊運行時,因爲如今的程序沒有通過編譯這一步,因此安裝的程序跟原來的同樣, 因此在console輸出的信息中會出現這一行信息: ActivityManager: Warning: Activity not started, its current task has been brought to the front  android

      但在調式的時候發現,這樣作能夠解決這個問題;首先在Package Explorer中找到要運行的程序,而後點擊右鍵,選中 refresh, 而後再選中run as -----> android application,最後解決了問題; app


可是當輸入完電話號碼,撥打的時候程序報錯以下:

LogCat顯示: eclipse

 threadid=1: thread exiting with uncaught exception (group=0x40015560)FATAL EXCEPTION: main ide

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.CALL dat=tel:1233453 } oop

at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1409)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
at android.app.Activity.startActivityForResult(Activity.java:2827)
at android.app.Activity.startActivity(Activity.java:2933)
at com.example.phone5.MainActivity$MyOnClickListener.onClick(MainActivity.java:36)
at android.view.View.performClick(View.java:2485)
at android.view.View$PerformClick.run(View.java:9080)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
12-12 08:50:47.134: I/Process(589): Sending signal. PID: 589 SIG: 9
this

通過對Logcat的分析能夠發現問題出如今這裏:(tel:這個標點有問題不是英文標點 spa

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.CALL dat=tel:1233453 } .net

總結:

1.最好所有用英文來寫整個程序,不要中英文來回切換,真的要寫中文的註釋,最好集中寫。
2.學會看LogCat本身找問題出如今哪裏(這是的問題)

相關文章
相關標籤/搜索