첫 번째로, 나는 안드로이드와 자바를 처음 사용합니다.다른 클래스의 메서드에서 호출 상태 표시 줄 알림
두 개의 클래스 인 main.class와 Note.class가 있습니다.
단추를 누를 때 내 main.class의 내 Note.class에서 알림 메서드를 호출하고 있습니다.
문제는 Note.class에서이 라인이다 : 상기 방법은 닫힐 강제
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
라고하면. 나는이 문제가 PendingIntent.getActivity (this, 0, notificationIntent, 0);에있는 "this"와 같다고 믿는다. 그러나 나는 그것을 바꿀 것이 확실하지 않다.
알림 코드가 기본 클래스에 있으면 제대로 작동합니다.
모든 안내에 대해 매우 감사하게 생각합니다.
편집 : 메인 클래스 : http://pastebin.com/05Yx0a48
Note.class :
package com.adamblanchard.remindme.com.adamblanchard;
import com.adamblanchard.remindme.R;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
public class Note extends Activity {
public CharSequence note = "not changed";
int HELLO_ID = 1;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setTitle("Remind Me!");
}
//Notification Method
public void callNotification() {
// TODO Auto-generated method stub
String ns = Context.NOTIFICATION_SERVICE;
final NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
int icon = R.drawable.launcher;
CharSequence tickerText = "Remind Me!";
long when = System.currentTimeMillis();
final Notification notification = new Notification(icon, tickerText, when);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
final Context context = getApplicationContext();
CharSequence contentTitle = "Remind Me!";
CharSequence contentText = note;
Intent notificationIntent = new Intent(context, AndroidNotifications.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
mNotificationManager.notify(HELLO_ID, notification);
HELLO_ID++;
}
}
디버그 출력 :
스레드 [< 1> 주 (정지됨 (IllegalStateException이 예외))
주 (활동) .getSystemService (문자열) 행 : 3536
Note.callNotification() 라인 37
remindme $ 1 $ 1.onClick (DialogInterface, INT) 라인 72에 AlertDialog (AlertController $ ButtonHandler) .handleMessage (메시지) 선 159 AlertController $ ButtonHandler (핸들러). dispatchMessage (메시지) 라인 99
Looper.loop() 선 123 ActivityThread.main (문자열 []) 라인 : 3647
Method.invokeNative (오브젝트가 오브젝트 [], 클래스 분류 [], 클래스, INT , 부울) line : 사용할 수 없음 [기본 메서드]
Method.invoke (Object, Object ...) 줄 : 507
ZygoteInit $ MethodAndArgsCaller.run() 줄 : 839,210 ZygoteInit.main (문자열 []) 라인 : 597 NativeStart.main (문자열 []) 라인 : 사용할 수 없습니다 [기본 방법]
이것은 내가 얻을 디버그 출력 플러스 힘 가까운 팝업에있다 장치.
Edit2가 :
매니페스트 XML :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.adamblanchard.remindme"
android:versionCode="3"
android:versionName="0.7">
<application android:label="@string/app_name" android:icon="@drawable/ic_launcher72">
<activity android:name=".com.adamblanchard.remindme" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Note">
<intent-filter>
<action android:name="Note" />
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="1"></uses-sdk>
</manifest>
스택 트레이스 (이 당신이 뜻은 무엇인가?) :
Thread [<1> main] (Suspended (exception ActivityNotFoundException))
Instrumentation.checkStartActivityResult(int, Object) line: 1404
Instrumentation.execStartActivity(Context, IBinder, IBinder, Activity, Intent, int) line: 1378
remindme(Activity).startActivityForResult(Intent, int) line: 2827
remindme(Activity).startActivity(Intent) line: 2933
remindme$1$1.onClick(DialogInterface, int) line: 82
AlertDialog(AlertController$ButtonHandler).handleMessage(Message) line: 159
AlertController$ButtonHandler(Handler).dispatchMessage(Message) line: 99
Looper.loop() line: 123
ActivityThread.main(String[]) line: 3647
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]
Method.invoke(Object, Object...) line: 507
ZygoteInit$MethodAndArgsCaller.run() line: 839
ZygoteInit.main(String[]) line: 597
NativeStart.main(String[]) line: not available [native method]
나 : 이 Note Note = new Note();
이는 Activity
을 인스턴스화하지 않도록 올바른 방법 입니다 : 당신의 remindme 활동에서
01-15 00:56:18.167: WARN/dalvikvm(14887): threadid=1: thread exiting with uncaught exception (group=0x40015560)
01-15 00:56:18.217: ERROR/AndroidRuntime(14887): FATAL EXCEPTION: main
01-15 00:56:18.217: ERROR/AndroidRuntime(14887): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.adamblanchard.remindme/com.adamblanchard.remindme.com.adamblanchard.Note}; have you declared this activity in your AndroidManifest.xml?
01-15 00:56:18.217: ERROR/AndroidRuntime(14887): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
01-15 00:56:18.217: ERROR/AndroidRuntime(14887): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
01-15 00:56:18.217: ERROR/AndroidRuntime(14887): at android.app.Activity.startActivityForResult(Activity.java:2827)
01-15 00:56:18.217: ERROR/AndroidRuntime(14887): at android.app.Activity.startActivity(Activity.java:2933)
01-15 00:56:18.217: ERROR/AndroidRuntime(14887): at com.adamblanchard.remindme.com.adamblanchard.remindme$1$1.onClick(remindme.java:82)
01-15 00:56:18.217: ERROR/AndroidRuntime(14887): at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:159)
01-15 00:56:18.217: ERROR/AndroidRuntime(14887): at android.os.Handler.dispatchMessage(Handler.java:99)
01-15 00:56:18.217: ERROR/AndroidRuntime(14887): at android.os.Looper.loop(Looper.java:123)
01-15 00:56:18.217: ERROR/AndroidRuntime(14887): at android.app.ActivityThread.main(ActivityThread.java:3647)
01-15 00:56:18.217: ERROR/AndroidRuntime(14887): at java.lang.reflect.Method.invokeNative(Native Method)
01-15 00:56:18.217: ERROR/AndroidRuntime(14887): at java.lang.reflect.Method.invoke(Method.java:507)
01-15 00:56:18.217: ERROR/AndroidRuntime(14887): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-15 00:56:18.217: ERROR/AndroidRuntime(14887): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-15 00:56:18.217: ERROR/AndroidRuntime(14887): at dalvik.system.NativeStart.main(Native Method)
01-15 00:56:18.237: WARN/ActivityManager(156): Force finishing activity com.adamblanchard.remindme/.com.adamblanchard.remindme
01-15 00:56:18.747: WARN/ActivityManager(156): Activity pause timeout for HistoryRecord{40a15868 com.adamblanchard.remindme/.com.adamblanchard.remindme}
01-15 00:56:18.777: DEBUG/Launcher(10740): -- loadPreferences()
01-15 00:56:19.177: INFO/ActivityManager(156): No longer want com.facebook.katana (pid 14395): hidden #16
01-15 00:56:29.177: WARN/ActivityManager(156): Activity destroy timeout for HistoryRecord{40a15868 com.adamblanchard.remindme/.com.adamblanchard.remindme}
메모 클래스의 코드를 표시 할 수 있습니까? 또한 오류 메시지에 대한 세부 정보를 알려주십시오. – elevine
"main"과 "note"는 둘 다 작동합니까? 자세한 내용을 게시하면 귀하의 질문에 대한 답변을 얻을 수 있습니다. – WorkerThread