I get this error when I run my program. It starts up the first page, but when it's supposed to go to .Menu it crashes:
11-04 06:01:06.039: W/dalvikvm(949): threadid=11: thread exiting with uncaught exception (group=0x414c4700)
11-04 06:01:06.057: E/AndroidRuntime(949): FATAL EXCEPTION: Thread-87
11-04 06:01:06.057: E/AndroidRuntime(949): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.example.secondapp.MENU }
11-04 06:01:06.057: E/AndroidRuntime(949): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1632)
11-04 06:01:06.057: E/AndroidRuntime(949): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
11-04 06:01:06.057: E/AndroidRuntime(949): at android.app.Activity.startActivityForResult(Activity.java:3390)
11-04 06:01:06.057: E/AndroidRuntime(949): at android.app.Activity.startActivityForResult(Activity.java:3351)
11-04 06:01:06.057: E/AndroidRuntime(949): at android.app.Activity.startActivity(Activity.java:3587)
11-04 06:01:06.057: E/AndroidRuntime(949): at android.app.Activity.startActivity(Activity.java:3555)
11-04 06:01:06.057: E/AndroidRuntime(949): at com.example.secondapp.Splash$1.run(Splash.java:26)
Here's my Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.secondapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".Splash"
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=".Menu"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MENU" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAINACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
And here are the .java files of my .Splash activity and my .Menu activity:
Splash
package com.example.secondapp;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
public class Splash extends Activity {
MediaPlayer ourSong;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
ourSong = MediaPlayer.create(Splash.this, R.raw.happyman);
ourSong.start();
Thread timer = new Thread(){
public void run(){
try{
sleep(5000);
} catch (InterruptedException e){
e.printStackTrace();
}finally{
Intent startMain = new Intent("com.example.secondapp.MENU");
startActivity(startMain);
}
}
};
timer.start();
}
#Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
finish();
}
}
Menu
package com.example.secondapp;
public class Menu extends ListActivity {
String classes[] = {"MainActivity", "example1", "example2", "example3", "example4", "example5"};
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(Menu.this, android.R.layout.simple_list_item_1, classes));
}
#Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
String Cheese = classes[position];
super.onListItemClick(l, v, position, id);
try{
Class ourClass = Class.forName("com.example.secondapp." + Cheese);
Intent ourIntent = new Intent(Menu.this, ourClass);
startActivity(ourIntent);
}catch(ClassNotFoundException e){
e.printStackTrace();
}
}
}
in your manifest the action should match. Change it with com.example.secondapp.MENU
It is in caps MENU should be Menu
Change to
Intent startMain = new Intent("com.example.secondapp.Menu");
coz your activity is public class Menu extends ListActivity { and in manifest you have
<activity
android:name=".Menu"
Edit:
Explicit intents designate the target component by its name (the
component name field, mentioned earlier, has a value set). Since
component names would generally not be known to developers of other
applications, explicit intents are typically used for
application-internal messages — such as an activity starting a
subordinate service or launching a sister activity.
Implicit intents do not name a target (the field for the component
name is blank). Implicit intents are often used to activate
components in other applications.
So Change to explicit intent
Intent startMain = new Intent(Splash.this,Menu.class); // in Splash.java
and in manifest
<activity
android:name="com.example.secondapp.Menu"
android:label="#string/app_name" >
</activity>
For more info check the docs
http://developer.android.com/guide/components/intents-filters.html
You need to set activity class in your manifest and you misspelled MENU
replace
<activity
android:name=".Menu"
android:label="#string/app_name" >
with
<activity
android:name=".MENU"
android:label="#string/app_name" >
Related
I want to know why it cannot open up new java class.
When I try to start new activity, it will be crash.
public class MainActivity extends ActionBarActivity {
EditText emailEt;
TextView registerET;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
emailEt = (EditText) findViewById(R.id.email);
registerET = (TextView) findViewById(R.id.register);
registerET.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Log.i("clicks","You Clicked register page");
Intent myIntent = new Intent(MainActivity.this, RegisterActivity.class);
startActivity(myIntent);
MainActivity.this.finish();
}
});
}
public void OnLogin(View view) {
String username = emailEt.getText().toString();
String type = "login";
BackgroundWorker backgroundWorker = new BackgroundWorker(this);
backgroundWorker.execute(type, username);
}
}
It's possible manifests problem? Am I put it wrong position for the activity?
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.a20_1discussboard">
<uses-permission android:name="android.permission.INTERNET"></uses-permission>"
<application
android:allowBackup="true"
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>
<activity android:label="#string/app_name" android:name=".RegisterActivity"/>
</manifest>
It look like can be open up new java class, but it still display MainActivity.
Error Log:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.a20_1discussboard, PID: 2194
java.lang.IllegalStateException: Could not find method onClick(View) in a parent or ancestor Context for android:onClick attribute defined on view class android.support.v7.widget.AppCompatTextView with id 'register'
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.resolveMethod(AppCompatViewInflater.java:327)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:284)
at android.view.View.performClick(View.java:4780)
at android.view.View$PerformClick.run(View.java:19866)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Put proper Menifest format:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.a20_1discussboard">
<uses-permission android:name="android.permission.INTERNET"></uses-permission>"
<application
android:allowBackup="true"
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>
<activity android:label="#string/app_name"
android:name=".RegisterActivity"/> //<---here
</application>
</manifest>
Don't call finish(), this caused your crash:
registerET.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Log.i("clicks","You Clicked register page");
Intent myIntent = new Intent(MainActivity.this, RegisterActivity.class);
startActivity(myIntent);
//remove finish();
}
});
Try declared activity in application in your AndroidManifest.xml like this.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.a20_1discussboard">
<uses-permission android:name="android.permission.INTERNET"></uses-permission>"
<application
android:allowBackup="true"
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>
<activity android:label="#string/app_name"
android:name=".RegisterActivity"/>
</application>
</manifest>
Be sure that you add RegisterActivity to your AndroidManifest.xml inside <application> tag:
<application ...>
...
<activity
android:label="#string/app_name"
android:name=".RegisterActivity"/>
</application>
Delete this line from onCreate method: MainActivity.this.finish();
If you want to stop or pause MainActivity, use:
#Override
public void onPause() { }
or
#Override
public void onStop() { }
in MainActivity class.
Thanks all.
Add RegisterActivity to AndroidManifest.xml inside <application> tag and remove MainActivity.this.finish()
It is working now.
I want to switch between two activity and I put an if statement, but after I resolve the startActivity method the app crashes:
activity1.java
public class StartActivity extends AppCompatActivity {
int count =0;
SQLiteDatabase db;
#Override
protected void onCreate(Bundle savedInstanceState) {
final Context context = this;
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_start);
db=openOrCreateDatabase("StopSmokeDB", Context.MODE_PRIVATE, null);
try {
Cursor mCount = db.rawQuery("select count(*) from UserTable", null);
mCount.moveToFirst();
count= mCount.getInt(0);
} catch (Exception e){
} finally {
if(count > 0){
finish();
Intent intent = new Intent(context, MainActivity.class);
startActivity(intent);
} else {
finish();
startActivity(new Intent(this,RegActivity.class));
}
}
}
}
androidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="tzahianidgar.stopsmoke.RegActivity"></activity>
<activity android:name="tzahianidgar.stopsmoke.StartActivity"></activity>
</application>
this is my logcat:
04-10 05:57:38.316 3630-3630/tzahianidgar.stopsmoke I/art: Not late-enabling -Xcheck:jni (already on)
04-10 05:57:38.602 3630-3630/tzahianidgar.stopsmoke W/System: ClassLoader referenced unknown path: /data/app/tzahianidgar.stopsmoke-1/lib/x86
04-10 05:57:38.733 3630-3630/tzahianidgar.stopsmoke W/System: ClassLoader referenced unknown path: /data/app/tzahianidgar.stopsmoke-1/lib/x86
Firstly you should close the Cursor after using like:
if(mCount != null)
mCount.close();
Secondly, You closed your current activity before starting a new one. Replace your finally block code with this:
finally {
if(mCount != null)
mCount.close();
if(count > 0){
startActivity(new Intent(StartActivity.this,MainActivity.class));
finish();
} else {
startActivity(new Intent(StartActivity.this,RegActivity.class));
finish();
}
}
I made an app using Parse as backend. I am able to get the notification but when i tap on it, the app crashes.
Here are the java and XML files.
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="chipset.lugmnotifier">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<permission
android:name="chipset.lugmnotifier.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="chipset.lugmnotifier.permission.C2D_MESSAGE" />
<application
android:name=".resources.ParseInitApplication"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<meta-data
android:name="com.parse.push.notification_icon"
android:resource="#drawable/ic_notification" />
<activity
android:name=".HomeActivity"
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=".AdminActivity"
android:label="#string/title_activity_admin"
android:parentActivityName=".HomeActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".HomeActivity" />
</activity>
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParseBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
<receiver
android:name="com.parse.ParsePushBroadcastReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
<receiver
android:name="com.parse.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="chipset.lugmnotifier" />
</intent-filter>
</receiver>
</application>
</manifest>
ParseInitApplication.java
import android.app.Application;
import android.util.Log;
import com.parse.Parse;
import com.parse.ParseException;
import com.parse.ParseInstallation;
import com.parse.ParsePush;
import com.parse.SaveCallback;
import static chipset.lugmnotifier.resources.Constants.APPLICATION_ID;
import static chipset.lugmnotifier.resources.Constants.CLIENT_KEY;
public class ParseInitApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
Parse.initialize(this, APPLICATION_ID, CLIENT_KEY);
ParsePush.subscribeInBackground("", new SaveCallback() {
#Override
public void done(ParseException e) {
if (e != null) {
Log.d("com.parse.push", "successfully subscribed to the broadcast channel.");
} else {
Log.e("com.parse.push", "failed to subscribe for push", e);
}
}
});
ParseInstallation.getCurrentInstallation().saveInBackground();
}
}
HomeActivity.java
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.text.method.PasswordTransformationMethod;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ListView;
import com.parse.FindCallback;
import com.parse.ParseAnalytics;
import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.ParseQuery;
import org.duncavage.swipetorefresh.widget.SwipeRefreshLayout;
import java.util.List;
import chipset.lugmnotifier.resources.Functions;
import chipset.lugmnotifier.resources.NotificationListViewAdapter;
import de.keyboardsurfer.android.widget.crouton.Crouton;
import de.keyboardsurfer.android.widget.crouton.Style;
import static chipset.lugmnotifier.resources.Constants.KEY_CLASS_NOTIFICATION;
import static chipset.lugmnotifier.resources.Constants.KEY_DETAIL;
import static chipset.lugmnotifier.resources.Constants.KEY_TITLE;
import static chipset.lugmnotifier.resources.Constants.PASSWORD;
public class HomeActivity extends Activity {
ListView notificationsListView;
SwipeRefreshLayout notificationSwipeRefreshLayout;
Functions functions = new Functions();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
ParseAnalytics.trackAppOpened(getIntent());
notificationSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.notificationSwipeRefreshLayout);
notificationsListView = (ListView) findViewById(R.id.notificationListView);
notificationSwipeRefreshLayout.setColorScheme(R.color.alizarin, R.color.emerald, R.color.peterRiver, R.color.sunFlower);
notificationSwipeRefreshLayout.setActionBarSwipeIndicatorText(R.string.swipe_to_refresh);
notificationSwipeRefreshLayout.setActionBarSwipeIndicatorRefreshingText(R.string.loading);
notificationSwipeRefreshLayout.setActionBarSwipeIndicatorBackgroundColor(
getResources().getColor(R.color.alizarin));
notificationSwipeRefreshLayout.setActionBarSwipeIndicatorTextColor(
getResources().getColor(R.color.clouds));
notificationSwipeRefreshLayout.setActionBarSwipeIndicatorRefreshingTextColor(
getResources().getColor(R.color.clouds));
notificationSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
#Override
public void onRefresh() {
new FetchData().getNotifications();
}
});
new FetchData().getNotifications();
}
private class FetchData {
public void getNotifications() {
if (functions.isConnected(getApplicationContext())) {
notificationSwipeRefreshLayout.setRefreshing(true);
ParseQuery<ParseObject> query = ParseQuery.getQuery(KEY_CLASS_NOTIFICATION);
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> parseObjects, ParseException e) {
notificationSwipeRefreshLayout.setRefreshing(false);
final String[] title = new String[parseObjects.size()];
final String[] detail = new String[parseObjects.size()];
if (e == null) {
for (int i = 0; i < parseObjects.size(); i++) {
title[i] = parseObjects.get(i).getString(KEY_TITLE);
detail[i] = parseObjects.get(i).getString(KEY_DETAIL);
}
notificationsListView.setAdapter(new NotificationListViewAdapter(getApplicationContext(), title, detail));
notificationsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Crouton.showText(HomeActivity.this, title[i] + " - " + detail[i], Style.INFO);
}
});
} else {
Crouton.showText(HomeActivity.this, e.getMessage(), Style.ALERT);
}
}
});
} else {
notificationSwipeRefreshLayout.setRefreshing(false);
Crouton.showText(HomeActivity.this, "No internet connection", Style.ALERT);
}
}
}
#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, 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();
if (id == R.id.action_admin) {
final EditText passwordEditText = new EditText(HomeActivity.this);
passwordEditText.setTransformationMethod(PasswordTransformationMethod.getInstance());
AlertDialog.Builder builder = new AlertDialog.Builder(HomeActivity.this);
builder.setTitle("Admin Panel");
builder.setMessage("Enter the admin password");
builder.setView(passwordEditText);
builder.setPositiveButton("LOGIN", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
if (passwordEditText.getText().toString().equals(PASSWORD)) {
startActivity(new Intent(HomeActivity.this, AdminActivity.class));
} else {
Crouton.showText(HomeActivity.this, "Incorrect Password", Style.ALERT);
}
}
});
builder.setNeutralButton("CANCEL", null);
builder.create();
builder.show();
}
return super.onOptionsItemSelected(item);
}
}
StackTrace (of the crash)
10:46:02.302 15739-15739/chipset.lugmnotifier E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: chipset.lugmnotifier, PID: 15739
java.lang.RuntimeException: Unable to start receiver com.parse.ParsePushBroadcastReceiver: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat= flg=0x1000c000 (has extras) }
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2414)
at android.app.ActivityThread.access$1700(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1272)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat= flg=0x1000c000 (has extras) }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1632)
at android.app.Instrumentation.execStartActivitiesAsUser(Instrumentation.java:1481)
at android.app.ContextImpl.startActivitiesAsUser(ContextImpl.java:1080)
at android.content.ContextWrapper.startActivitiesAsUser(ContextWrapper.java:344)
at android.content.ContextWrapper.startActivitiesAsUser(ContextWrapper.java:344)
at android.app.TaskStackBuilder.startActivities(TaskStackBuilder.java:221)
at android.app.TaskStackBuilder.startActivities(TaskStackBuilder.java:232)
at android.app.TaskStackBuilder.startActivities(TaskStackBuilder.java:208)
at com.parse.TaskStackBuilderHelper.startActivities(TaskStackBuilderHelper.java:19)
at com.parse.ParsePushBroadcastReceiver.onPushOpen(ParsePushBroadcastReceiver.java:202)
at com.parse.ParsePushBroadcastReceiver.onReceive(ParsePushBroadcastReceiver.java:108)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2407)
at android.app.ActivityThread.access$1700(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1272)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
I want to open HomeActivity on notification tap. Any help will be appreciated. If any other file is required, please let me know I'll add it.
Quoting from below post by Ahmad Raza
Exception when opening Parse push notification
You can extend ParsePushBroadcastReceiver and override onPushOpen method.
public class Receiver extends ParsePushBroadcastReceiver {
#Override
public void onPushOpen(Context context, Intent intent) {
Log.e("Push", "Clicked");
Intent i = new Intent(context, HomeActivity.class);
i.putExtras(intent.getExtras());
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
Use it in manifest, (Instead of using ParsePushBroadcastReceiver)
<receiver
android:name="your.package.name.Receiver"
android:exported="false" >
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
After a long effort, it worked for me:
ParsePushApplication.java
public class ParsePushApplication extends Application {
#Override
public void onCreate(){
super.onCreate();
Parse.initialize(this, "App_Key", "Client_Key");
ParseInstallation.getCurrentInstallation().saveInBackground();
}
}
MainActivity.java
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ParseAnalytics.trackAppOpenedInBackground(getIntent());
try {
Intent intent = getIntent();
Bundle extras = intent.getExtras();
if (extras != null) {
String jsonData = extras.getString("com.parse.Data");
JSONObject json;
json = new JSONObject(jsonData);
String pushStore = json.getString("alert");
Toast.makeText(MainActivity.this, pushStore, Toast.LENGTH_LONG).show();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Receiver.java
public class Receiver extends ParsePushBroadcastReceiver {
private static final String TAG = "MyNotificationsReceiver";
#Override
public void onPushOpen(Context context, Intent intent) {
Log.e("Push", "Clicked");
Intent i = new Intent(context, MainActivity.class);
i.putExtras(intent.getExtras());
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="your.package.name">
<!-- IMPORTANT: Change "your.package.name" to match your app's package name. -->
<application
android:name=".ParsePushApplication"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<meta-data
android:name="com.parse.push.notification_icon"
android:resource="#drawable/push_icon"/>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParseBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
<receiver
android:name="your.package.name.Receiver"
android:exported="false" >
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
<receiver android:name="com.parse.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<!--
IMPORTANT: Change "your.package.name" to match your app's package name.
-->
<category android:name="your.package.name" />
</intent-filter>
</receiver>
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!--
IMPORTANT: Change "your.package.name.permission.C2D_MESSAGE" in the lines below
to match your app's package name + ".permission.C2D_MESSAGE".
-->
<permission android:protectionLevel="signature"
android:name="your.package.name.permission.C2D_MESSAGE" />
<uses-permission android:name="com.zeeroapps.parsetutorial_cli.permission.C2D_MESSAGE" />
</manifest>
Okay so I've been messing around with the Twitter API, and all of a sudden I've started to get the ClassNotFoundException error code when I try and enter the Activity which has my login box to sign into Twitter.
Here's the error code.
2398-2398/josh.com.twitterapi E/dalvikvm﹕ Could not find class 'josh.com.twitterapi.LoginActivity', referenced from method josh.com.twitterapi.NavigationDrawerFragment.selectItem
07-05 02:19:30.138 2398-2398/josh.com.twitterapi E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: josh.com.twitterapi.LoginActivity
at josh.com.twitterapi.NavigationDrawerFragment.selectItem(NavigationDrawerFragment.java:204)
at josh.com.twitterapi.NavigationDrawerFragment.access$000(NavigationDrawerFragment.java:32)
at josh.com.twitterapi.NavigationDrawerFragment$1.onItemClick(NavigationDrawerFragment.java:99)
at android.widget.AdapterView.performItemClick(AdapterView.java:301)
at android.widget.AbsListView.performItemClick(AbsListView.java:1280)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:3071)
at android.widget.AbsListView$1.run(AbsListView.java:3973)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4867)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1007)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774)
at dalvik.system.NativeStart.main(Native Method)
07-05 02:21:03.973 3223-3223/josh.com.twitterapi E/dalvikvm﹕ Could not find class 'josh.com.twitterapi.LoginActivity', referenced from method josh.com.twitterapi.NavigationDrawerFragment.selectItem
This is my LoginActivity.java.
package josh.com.socialme;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import com.codepath.oauth.OAuthLoginActivity;
public class LoginActivity extends OAuthLoginActivity<TwitterClient> {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
}
// Inflate the menu; this adds items to the action bar if it is present.
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.login, menu);
return true;
}
// OAuth authenticated successfully, launch primary authenticated activity
// i.e Display application "homepage"
#Override
public void onLoginSuccess() {
// Intent i = new Intent(this, PhotosActivity.class);
// startActivity(i);
}
// OAuth authentication flow failed, handle the error
// i.e Display an error dialog or toast
#Override
public void onLoginFailure(Exception e) {
e.printStackTrace();
}
// Click handler method for the button used to start OAuth flow
// Uses the client to initiate OAuth authorization
// This should be tied to a button used to login
public void loginToRest(View view) {
getClient().connect();
}
}
This is my AndroidManifest.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="josh.com.socialme" >
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.AppCompat.Light.DarkActionBar" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<activity
android:name=".Hub"
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=".Feed"
android:label="#string/title_activity_feed" >
</activity>
<activity
android:name=".LoginActivity"
android:label="#string/app_name" >
</activity>
</application>
</manifest>
And this is my method I use to get to the activity.
private void selectItem(int position) {
// Handle Navigation Options
Intent intent;
switch (position) {
case 1:
intent = new Intent(getActivity(), Feed.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
getActivity().startActivity(intent);
break;
case 2:
intent = new Intent(getActivity(), LoginActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
getActivity().startActivity(intent);
break;
}
}
I would greatly appreciate it if someone could point me towards the right direction.
Kind regards,
Josh
(AndroidManifest.xml as requested)
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="josh.com.socialme" >
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.AppCompat.Light.DarkActionBar" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<activity
android:name=".Hub"
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=".Feed"
android:label="#string/title_activity_feed" >
</activity>
<activity
android:name=".LoginActivity"
android:label="#string/title_login_activity" >
</activity>
</application>
</manifest>
My app crashes when changing activity Here is my code,
I was following a tutorial on youtube, Everything seems to be exactly like his code. See if you can help
Everything seems to be inorder, I copyed everything exactly,
Manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.helloworld"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".Splash"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="com.example.helloworld.MAINACTIVITY" />
<category android:name="android.intent.category.DEFUALT" />
</intent-filter>
</activity>
</application>
</manifest>
MainActivity:
package com.example.helloworld;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.app.Activity;
public class MainActivity extends Activity {
int counter;
Button add, sub;
TextView display;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
counter = 0;
add = (Button) findViewById(R.id.bAdd);
sub = (Button) findViewById(R.id.bSub);
display = (TextView) findViewById(R.id.tvDisplay);
add.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
counter++;
display.setText("Your Total is " + counter);
}
});
sub.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
counter--;
display.setText("Your Total is " + counter);
}
});
}
}
Splash.java:
package com.example.helloworld;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class Splash extends Activity{
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Thread timer = new Thread(){
public void run(){
try{
sleep(5000);
} catch (InterruptedException e){
e.printStackTrace();
}finally{
Intent openStartingPoint = new Intent("com.example.helloworld.MAINACTIVITY");
startActivity(openStartingPoint);
}
}
};
timer.start();
}
}
Logcat:
07-19 20:35:36.068: E/AndroidRuntime(1442): FATAL EXCEPTION: Thread-74
07-19 20:35:36.068: E/AndroidRuntime(1442): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.example.helloworld.MAINACTIVITY }
07-19 20:35:36.068: E/AndroidRuntime(1442): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1512)
07-19 20:35:36.068: E/AndroidRuntime(1442): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1384)
07-19 20:35:36.068: E/AndroidRuntime(1442): at android.app.Activity.startActivityForResult(Activity.java:3190)
07-19 20:35:36.068: E/AndroidRuntime(1442): at android.app.Activity.startActivity(Activity.java:3297)
07-19 20:35:36.068: E/AndroidRuntime(1442): at com.example.helloworld.Splash$1.run(Splash.java:23)
Try changing:
Intent openStartingPoint = new Intent("com.example.helloworld.MAINACTIVITY");
To:
Intent openStartingPoint = new Intent(Splash.this, MainActivity.class);
I think the application crashes because you misspelled "DEFAULT" in the intent-filter.