ActivityManager:警告:活动未启动,其当前任务已被带到前面

Dav*_*vid 37 eclipse android bluetooth

package supa.mack.doppler;

import java.util.Set;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.bluetooth.*; 
import android.widget.Toast;

public class doppler_test extends Activity {
TextView out;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

out = (TextView) findViewById(R.id.out);

// Getting the Bluetooth adapter
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
out.append("\nAdapter: " + adapter);

// Check for Bluetooth support in the first place 
// Emulator doesn't support Bluetooth and will return null
if(adapter==null) { 
out.append("\nBluetooth NOT supported. Aborting.");
return;
}

// Starting the device discovery
out.append("\nStarting discovery...");
adapter.startDiscovery();
out.append("\nDone with discovery...");

// Listing paired devices
out.append("\nDevices Pared:");
Set<BluetoothDevice> devices = adapter.getBondedDevices();
for (BluetoothDevice device : devices) {
out.append("\nFound device: " + device);
}

Button searchButton=(Button) findViewById(R.id.search_button);
searchButton.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
Intent intent=new Intent(
doppler_test.this,
search_result.class
);

startActivity(intent);
}
}); 
}
} 
Run Code Online (Sandbox Code Playgroud)

-------------------------------------- ...

这是问题所在的代码....

当我运行android模拟器时,它并没有给我一个错误

"[2010-08-25 09:12:42 - doppler_test] ActivityManager: Warning: Activity not started, its current task has been brought to the front"
Run Code Online (Sandbox Code Playgroud)

我认为这意味着蓝牙功能和按钮意图的意图仅在层次结构系统上运行.我的意思是,如果我将按钮操作器移动到蓝牙之上,按钮就可以工作,但是当前应用程序运行时蓝牙有效,但是当我按下搜索按钮时没有任何反应.

还有什么可能有用的是我的按钮的XML代码,所以这里......

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
xmlns:android="http://schemas.android.co…
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal"
android:background="@color/purple_flurp"…
<TextView 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:text="@string/hello"/>
<Button
android:id="@+id/search_button"
android:layout_height="wrap_content" 
android:text="@string/search" 
android:layout_width="fill_parent"/>

<TextView 
android:text="@+id/TextView01" 
android:id="@+id/out" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content">
</TextView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

-------------------------------------- ...

有任何想法吗?什么都会很棒!谢谢

Fal*_*rri 56

您是否在启动应用程序或单击按钮时收到警告?如果您从eclipse运行应用程序而不必重新编译(即没有代码更改),它不会通过卸载安装过程,它只是将应用程序推送到前面,就像您从手机中恢复它一样.这不是错误,而是"按预期工作"

  • 添加到Falmari,@ David只需执行Project> Clean即可重新编译项目 (30认同)

小智 23

这个问题在eclipse上使用adt插件很明显.主要问题是...您的应用程序是在模拟器/设备上启动的,现在您尝试重新启动它而不对源代码进行任何更改.可能的解决方案:1重建项目并再次启动应用程序(需要更多时间)2为代码添加一些空格/新行并再次启动应用程序

我更喜欢第二种选择.但恕我直言,我认为它在侧插件的开发人员的愚蠢问题