ActivityManager:警告:活动未启动,其当前任务已被带到前面不断弹出?

时间:2014-07-24 15:42:02

标签: android

我是Android开发工具世界的新手,我刚刚在笔记本电脑上下载了Eclipse和ADT插件。我只是按照我在线观看的视频教程制作了一个按钮,它在模拟器上不起作用,所以我尝试将我的Android手机连接到笔记本电脑并下载所需的驱动程序。在Android设备上,程序包本身会弹出,但我制作的按钮不会。消息

  

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

在说完以下所有内容后,

总是会在控制台上弹出:

Android Launch! 
[2014-07-24 08:22:11 - PLEASEBUTTON] adb is running normally. 
[2014-07-24 08:22:11 - PLEASEBUTTON] Performing com.example.pleasebutton.MainActivity activity launch 
[2014-07-24 08:22:13 - PLEASEBUTTON] Application already deployed. No need to reinstall. 
[2014-07-24 08:22:13 - PLEASEBUTTON] Starting activity com.example.pleasebutton.MainActivity on device 3934C3A970FE00EC 
[2014-07-24 08:22:13 - PLEASEBUTTON] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.pleasebutton/.MainActivity } 
[2014-07-24 08:22:14 - PLEASEBUTTON] ActivityManager: Warning: Activity not started, its current task has been brought to the front

我仍然不知道发生了什么,我真的想解决这个问题。

package com.example.pleasebutton;

import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.os.Build;
import android.app.Activity;
import android.view.View;
import android.widget.Toast;


public class MainActivity extends Activity implements View.OnClickListener{

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


 }
 public void onClick(View v){}   
 public void buttonBtn (View v) {
     Toast.makeText(this,"You just pressed a button",Toast.LENGTH_LONG).show();

 }
}

这是活动xml文件

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.pleasebutton.MainActivity"
tools:ignore="MergeRootFrame" />

这里是片段xml文件

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.pleasebutton.MainActivity$PlaceholderFragment" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world" />

<Button
    android:id="@+id/awesomebutton"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:onClick="buttonBtn"
    android:text="Cool Button" />

1 个答案:

答案 0 :(得分:0)

试试这段代码:

public class MainActivity extends Activity {

    private Button bAfficher;


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


        // Assign graphical button to attribute

        bAfficher = (Button) this.findViewById(R.id.awesomebutton);



        bAfficher.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                 Toast.makeText(this,"You just pressed a button",Toast.LENGTH_LONG).show();

 }
});
}
}