2017-09-22 2 views
0

SoNach einer entsprechenden Meldung klicken, wird neue Tätigkeit nicht starten

Ich versuche, meine zweite Tätigkeit zu starten, die „dummy.class“ ist

der Code, für die sich hier:

import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.widget.Toast; 

public class dummy extends AppCompatActivity { 

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

Ich versuche, dies zu tun, wenn ich die Benachrichtigung klicken, die durch diesen Code in meinem MainActivity generiert:

public class MainActivity extends AppCompatActivity 
{ 

int notifyId = 1; 
int messages = 0; 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    Button b1 = (Button) findViewById(R.id.gen_notif); 

} 


public void createNotif(View v) 
{ 
    messages += 1; 
    notifyId += 1 ; 
    NotificationManager notificationManager=(NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
    Intent intent=new Intent(MainActivity.this ,dummy.class); 
    PendingIntent pendingIntent = PendingIntent.getActivity(this,(int) System.currentTimeMillis(),intent,0); 
    NotificationCompat.Builder n = (NotificationCompat.Builder) new NotificationCompat.Builder(this) 
      .setContentTitle("Hello") 
      .setContentText("Hello World Notification") 
      .setContentIntent(pendingIntent) 
      .setSmallIcon(R.mipmap.ic_launcher) 
      .setNumber(messages) 
      .setAutoCancel(true); 
    notificationManager.notify(notifyId,n.build()); 
} 

Hier ist der XML für activity_main:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="com.manan.notif.MainActivity"> 

<Button 
    android:id="@+id/gen_notif" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/b_text" 
    android:onClick="createNotif" 
    app:layout_constraintBottom_toBottomOf="parent" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintRight_toRightOf="parent" 
    app:layout_constraintTop_toTopOf="parent" /> 

</android.support.constraint.ConstraintLayout> 

Aber wenn ich auf die Benachrichtigung klicke, tut es nichts (außer sich wegen des Codes zu entlassen). Ich lerne gerade, also weiß ich nicht, was ich falsch mache, könnte ein anderes Paar Augen benutzen.

Antwort

1

Ok, es war ein dummer Fehler, wie ich dachte, ich habe vergessen, die neue Klasse in die Manifest-Datei als eine Aktivität hinzufügen möchten, einfach das Hinzufügen es fest:

<activity android:name="dummy" 
     android:label="@string/app_name"> 
     <intent-filter> 
      <action android:name="android.intent.action.VIEW" /> 
     </intent-filter> 
    </activity> 
Verwandte Themen