![](/img/trans.png)
[英]ActivityManager: Warning: Activity not started, its current task has been brought to the front
[英]ActivityManager: Warning: Activity not started, its current task has been brought to the front keeps popping up?
我是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" />
試試這個代碼:
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();
}
});
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.