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

解决思路:百度(有了问题自己分析考虑过后没找到思路问百度) 也就是在修改了代码后,在没有重新编译这步, 模拟器原来的.apk就不会经过卸载跟重新安装这一步;所以当在eclipse中只是点击运行时,由于现在的程序没有经过编译这一步,所以安装的程序跟原来的一样, 所以在console输出的信息中会出现这一行信息: ActivityManager: Warning: Activity not started, its current task has been brought to the front 

      但在调式的时候发现,这样做可以解决这个问题;首先在Package Explorer中找到要运行的程序,然后点击右键,选中 refresh, 然后再选中run as -----> android application,最后解决了问题;


但是当输入完电话号码,拨打的时候程序报错如下:

ActivityManager: Warning: Activity not started, it

LogCat显示:

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

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

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

经过对Logcat的分析可以发现问题出现在这里:(tel:这个标点有问题不是英文标点

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

总结:

1.最好全部用英文来写整个程序,不要中英文来回切换,真的要写中文的注释,最好集中写。
2.学会看LogCat自己找问题出现在哪里(这是的问题)

你可能感兴趣的:(android,异常,ActivityManage)