2012-03-09 10 views
10

Mam problem. Chcę otworzyć działanie za pomocą przycisku, ale cały czas się zawiesza. Stworzyłem 2 Klasy i Przycisk A. Ale ciągle się zawiesza.Rozpocznij aktywację za pomocą przycisku Android

  1. Klasa to klasa_o_aktywności(), a druga to klasa schedule_act().

activity_home klasy: klasa

package my.action.bat; 

    import android.app.Activity; 
    import android.content.Intent; 
    import android.os.Bundle; 
    import android.view.View; 
    import android.widget.Button; 

    public class activity_home extends Activity { 

     private Button ScheduleBtn; 

     @Override 
     protected void onCreate(Bundle savedInstanceState) { 
      // TODO Auto-generated method stub 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.main); 

      ScheduleBtn = (Button) findViewById(R.id.home_btn_schedule); 

      ScheduleBtn.setOnClickListener(new View.OnClickListener() { 

       public void onClick(View v) { 
        // TODO Auto-generated method stub 


        Intent myIntent = new Intent("my.action.bat.schedule_act"); 
        startActivity(myIntent); 


       } 
      }); 
     } 





    } 

schedule_act:

package my.action.bat; 

    import android.app.Activity; 
    import android.os.Bundle; 

    public class schedule_act extends Activity { 

     @Override 
     protected void onCreate(Bundle savedInstanceState) { 
      // TODO Auto-generated method stub 
      super.onCreate(savedInstanceState); 

      setContentView(R.layout.schedule_layout); 
     } 



    } 

Android Oczywisty:

<?xml version="1.0" encoding="utf-8"?> 
    <manifest xmlns:android="http://schemas.android.com/apk/res/android" 
     package="my.action.bat" 
     android:versionCode="1" 
     android:versionName="1.0" > 

     <uses-sdk android:minSdkVersion="8" /> 

     <application 
      android:icon="@drawable/ic_launcher" 
      android:label="@string/app_name" > 
      <activity 
       android:label="@string/app_name" 
       android:name=".activity_home" > 
       <intent-filter > 
        <action android:name="android.intent.action.MAIN" /> 

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

      <activity 
       android:label="@string/app_name" 
       android:name=".schedule_act" > 
       <intent-filter > 
        <action android:name="my.action.bat.SCHEDULE_ACT" /> 

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

    </manifest> 

Dziękuję bardzo.

+0

Co stanowi wyjątek wyrzucony? –

Odpowiedz

18

W przypadku intencji rozróżniana jest wielkość liter. Zmień

"my.action.bat.schedule_act" 

Aby

"my.action.bat.SCHEDULE_ACT" 

Ponadto, chyba że naprawdę trzeba używać intencji, chciałbym rozpocząć działalność jak tak

startActivity(new Intent(this, schedule_act.class)); 

Gdzie this jest Context podklasa

1

Musisz dodać wszystkie klasy aktywności do pliku manifestu !!

+1

Zrobił .... sprawdź ostatnią listę "" w kodzie, który zamieścił. –

2

Spróbuj zmienić linię

Intent myIntent = new Intent("my.action.bat.schedule_act"); 

Aby

Intent myIntent = new Intent(v.getContext(), schedule_act.class); 

i sprawdzić, czy to pomaga.

Aby uzyskać więcej informacji, patrz here.

3

Spróbuj

localIntent = new Intent(activity_home.this, schedule_act.class); 
    activity_home.this.startActivity(localIntent); 
2

Można zmienić ten wiersz

Intent myIntent = new Intent("my.action.bat.schedule_act"); startActivity(myIntent);

Aby coś takiego

Intent intent = new Intent ("Your context", "Your activity to launch"); startActivity(intent);

Pamiętaj, zawsze wskaż kontekst i działanie.

Powiązane problemy