第一次 用虚拟机跑android程序时,总是出现这个warning
贴出代码与console信息
activity_main.xml
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="姓名"
android:textSize="28sp"
/>
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/textView1"
android:layout_alignParentRight="true"
android:layout_marginRight="17dp"
android:ems="10"
android:hint="请输入姓名" />
MainActivity
package com.example.test;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 将布局XML文件引入activity中
setContentView(R.layout.activity_main);
}
@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;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
控制台提示
[2014-08-21 22:47:39 - test] ------------------------------
[2014-08-21 22:47:39 - test] Android Launch!
[2014-08-21 22:47:39 - test] adb is running normally.
[2014-08-21 22:47:39 - test] Performing com.example.test.MainActivity activity launch
[2014-08-21 22:47:40 - test] Application already deployed. No need to reinstall.
[2014-08-21 22:47:40 - test] Starting activity com.example.test.MainActivity on device 94488e54
[2014-08-21 22:47:41 - test] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.test/.MainActivity }
[2014-08-21 22:47:41 - test] ActivityManager: Warning: Activity not started, its current task has been brought to the front
PHP中文网2017-04-17 11:52:50
這只是一個警告訊息,並不是錯誤,系統只是透過這個訊息告訴你,你的Eclipse將要調試的程式和你目前虛擬機器正在運行的程式一模一樣,並且因為你原來的程式已經在虛擬機器上運行,所以系統不會殺死他或重啟他,只是把這個原來的程式帶到前台(當前運行),這很正常。
如果你稍微修改下你的程式碼然後再運行或把這個程式關掉再運行,這個警告就不會再有了。因為他已經被殺或重啟了。譯自http://stackoverflow.com/questions/3781182/activity-not-started-its-current-task-has-been-brought-to-the-front