应用程序导致设备运行缓慢

时间:2016-02-26 07:30:41

标签: java android xml butterknife

我最近听说过Butterknife api,所以我决定制作一个小巧的应用程序来熟悉它。但是,当我尝试运行我的代码时,会出现一个通知,告诉我应用程序导致我的手机运行缓慢,它会占用设备的内存,而不会产生错误堆栈。有人能告诉我这个问题是什么吗?

MainActivity.java

public List<TreeNode> FindIndex(TreeNodeCollection nodes, List<TreeNode> list)
{
    int idx;
    foreach (TreeNode Node in nodes)
    {
        if (Node.Text == "test")
        {
            idx = Node.Index;
            list.Add(Node);
        }
        else
        {
            MessageBox.Show("This XML file does not contain any node with name \"test\"!");
            return list;
        }
        FindIndex(Node.Nodes, list);
    }
    return list;
}

activity_main.xml中

public class MainActivity extends AppCompatActivity {
Context context = getApplicationContext();
CharSequence text = "It's ALIVE!!";
int duration = Toast.LENGTH_SHORT;

@Bind(R.id.button_main_one) Button button;

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

@OnClick(R.id.button_main_one)
public void button_clicked()
{
    Toast toast = Toast.makeText(context,text, duration);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.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();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}}

的AndroidManifest.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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">

<Button
    android:id="@+id/button_main_one"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Click Here"/>

<?xml version="1.0" encoding="utf-8"?>

的build.gradle

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

0 个答案:

没有答案