I am new to the Android Development Tools world and i just downloaded the Eclipse and ADT plugin on my laptop. I just made a button by following a video tutorial I watched online and it wouldn't work on the emulator, so I tried connecting my android phone to the laptop and downloaded the drivers needed. On the android device the package itself would pop up, but the button I made would not. The message
ActivityManager: Warning: Activity not started, its current task has been brought to the front
would always pop up on the console after saying all of the following:
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
I still have no idea what is going on, and I really want to solve this.
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();
}
}
here is the activity xml file
<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" />
and here is the fragment xml file
<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" />
Try this code :
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();
}
});
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.