Android - ClassNotFoundException (TwitterAPI) - java

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>

Related

Insert NewChidldActivity in-Between MainActivity and FirstChildAcvitity And Change Default ChildActivity to the NewChildActivity

Fellow Friends,
thank you all for your usual support.
I have developed an an examination app with login functionality.
Previously, the app had 3 Activities (MainActivity, WelcomeScreenActivity and QuestionsAcvitity). This app is working perfectly.
However, when the user logs in from the MainActivity, the WelcomeScreenActivity shows.
But I need to INSERT another activity (PROFILE_ACTIVITY) between the MainActivity and the WelcomeScreenActivity so that, when the user logs in successfully, the app will display the user's PROFILEACTIVITY.
Pictures below the page
Previous Code before the new ProfileActivity
MainActivity.java code
#Override
protected void onPostExecute(Void result){
if (!responseData.equals( "User Not Found" )) {
message = "Welcome";
data = responseData;//store the user id from the server in data
//Bundle bundle = new Bundle();//bundle the message and parse it to the next activity
//bundle.putString("dispMsg", message);//bundle the message using the variable dispMsg
//intent.putExtras(bundle);
startActivity(intent);
statusBar.setText(message);
} else {
message = responseData;//"Incorrect Username or Password. Try again!";
statusBar.setText(message);
}
super.onPostExecute(result);
}
DisplayWelcomeScreenActivity.java code
This activity displays after a successful login.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_welcome_screen);
// Get the Intent that started this activity and extract the string
intent = getIntent();
}
To pass from this WelcomeActivity to the next QuestionsActivity, the code below does that on buttonclick() event
public void courseClicked(View v) {
String course = "";
Intent intent = new Intent(this, CSS_342_Questions.class);
int qNum = 0;
switch (v.getId()){
case R.id.buttonCSS342:
course = "CSS 342";
qNum=1;
break;
case R.id.buttonCSS352:
course = "CSS 352";
qNum=1;
break;
case R.id.buttonCSS354:
course = "CSS 354";
qNum=1;
break;
case R.id.buttonCSS356:
course = "CSS 356";
qNum=1;
break;
case R.id.buttonCSS381:
course = "CSS 381";
qNum=1;
break;
case R.id.buttonPCR362:
course = "PCR 362";
qNum=1;
break;
}
Bundle bundle = new Bundle();
bundle.putString("dispCode", course);
bundle.putInt("qNum", qNum);
//bundle.putString("dispMsg", "Welcome");
intent.putExtras(bundle);
startActivity(intent);
}
The QuestionsActivity gets displayed using the code below.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_css_342__questions);
// Get the Intent that started this activity and extract the string
intent = getIntent();
bundle = getIntent().getExtras();
showCode = bundle.getString("dispCode");
qNum = bundle.getInt("qNum");
}
This code below is the Manifest xml that links the 3 activities together for proper navigation.
AndroidManifest.XML code
?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.examinationportal">
<uses-permission
android:name="android.permission.INTERNET"
android:required="true" />
<uses-permission
android:name="android.permission.ACCESS_NETWORK_STATE"
android:required="true" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.AppCompat.DayNight.DarkActionBar">
<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=".DisplayWelcomeScreen"
android:label="#string/welcome_screen_title"
android:parentActivityName=".MainActivity">
<!-- The meta-data tag is required if you support API level 15 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity
android:name=".CSS_342_Questions"
android:allowTaskReparenting="true"
android:label="#string/question_screen"
android:parentActivityName=".DisplayWelcomeScreen">
<!-- The meta-data tag is required if you support API level 15 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".DisplayWelcomeScreen" />
</activity>
<activity
android:name=".RegisterUserActivity"
android:label="#string/new_user_form"
android:parentActivityName=".MainActivity">
<!-- The meta-data tag is required if you support API level 15 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
</application>
</manifest>
Now, I want to insert a new activity (ProfileActivity) between the MainActivity and the DisplayScreenActivity.
I have changed the AndroidManifest xml code below.
The app is crashing. The LogCat shows the line where the app is crashing **StartActivity(intent)** in MainActivity.java; line 153
The Code After the new Activity
The MainActivity code still remains the same.
The new AndroidManifest.xml code
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.examinationportal">
<uses-permission
android:name="android.permission.INTERNET"
android:required="true" />
<uses-permission
android:name="android.permission.ACCESS_NETWORK_STATE"
android:required="true" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.AppCompat.DayNight.DarkActionBar">
<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=".ProfileAcvitity"
android:label="#string/student_profile"
android:parentActivityName=".MainActivity">
<!-- The meta-data tag is required if you support API level 15 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity
android:name=".RegisterUserActivity"
android:label="#string/new_user_form"
android:parentActivityName=".MainActivity">
<!-- The meta-data tag is required if you support API level 15 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
</application>
</manifest>
New ProfileActivity.java code
public class ProfileAcvitity extends AppCompatActivity {
public Intent intent;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile_acvitity);
intent = getIntent();
}
LOGCAT INFORMATION
04-25 13:53:33.680 14789-14789/com.example.examinationportal E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.examinationportal, PID: 14789
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.examinationportal/com.example.examinationportal.DisplayWelcomeScreen}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1805)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1523)
at android.app.Activity.startActivityForResult(Activity.java:4034)
at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:50)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:79)
at android.app.Activity.startActivityForResult(Activity.java:3986)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:859)
at android.app.Activity.startActivity(Activity.java:4325)
at android.app.Activity.startActivity(Activity.java:4293)
at com.example.examinationportal.MainActivity$GetText.onPostExecute(MainActivity.java:153)
at com.example.examinationportal.MainActivity$GetText.onPostExecute(MainActivity.java:83)
at android.os.AsyncTask.finish(AsyncTask.java:651)
at android.os.AsyncTask.-wrap1(AsyncTask.java)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:668)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5763)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
Please help me solve this problem.
Thank you.
<activity android:name=".DisplayWelcomeScreen"
android:label="#string/student_welcome"
android:parentActivityName=".MainActivity">
<!-- The meta-data tag is required if you support API level 15 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
Adding those lines in your AndroidManifest.xml file will solve your problem.

Android application failed to start activity

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.

when i want to test my app with a real device the app doesnt start

I've been trying to test my app where I'm implementing a G+ sign in and when I run it in the emulator with Android Studio the app runs but says that I need to update Google Play Services.
I've been struggling to do that so I thought that I would just test it on a real device but when I do the app doesn't start/run. When I go to settings and apps on device I can see that the app is installed but it doesn't show up in the app drawer or anywhere else.
I get this exception under my run tab in the bottom left corner:
java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.madchallenge2016edwindaniel.upbirdwatchers/.LoginActivity } from null (pid=20620, uid=2000) not exported from uid 10154
at android.os.Parcel.readException(Parcel.java:1425)
at android.os.Parcel.readException(Parcel.java:1379)
at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:1948)
at com.android.commands.am.Am.runStart(Am.java:463)
at com.android.commands.am.Am.run(Am.java:108)
at com.android.commands.am.Am.main(Am.java:81)
at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:276)
at dalvik.system.NativeStart.main(Native Method)
Here is my manifest:
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<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"
android:label="#string/title_activity_main"
android:theme="#style/AppTheme.NoActionBar" />
<intent-filter >
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<activity android:name=".RegisterActivity" />
<activity android:name=".LoginActivity" />
</application>
Here is the code of my launch activity:
package com.madchallenge2016edwindaniel.upbirdwatchers;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.google.android.gms.auth.api.Auth;
import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
import com.google.android.gms.auth.api.signin.GoogleSignInResult;
import com.google.android.gms.common.SignInButton;
import com.google.android.gms.common.api.GoogleApiClient;
import android.view.View;
import com.google.android.gms.common.ConnectionResult;
public class LoginActivity extends AppCompatActivity implements
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener{
private GoogleApiClient mGoogleApiClient;
private SignInButton mSignInButton;
private static final int RC_SIGN_IN = 9001;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
//Background
getWindow().setBackgroundDrawableResource(R.drawable.login_background);
// Configure sign-in to request the user's ID, email address, and basic
// profile. ID and basic profile are included in DEFAULT_SIGN_IN.
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.build();
// Build a GoogleApiClient with access to the Google Sign-In API and the
// options specified by gso.
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
SignInButton mSignInButton = (SignInButton)findViewById(R.id.sign_in_button);
mSignInButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.sign_in_button:
signIn();
break;
// ...
}
}
});
}
//Start sign in
private void signIn() {
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, RC_SIGN_IN);
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
if (requestCode == RC_SIGN_IN) {
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
handleSignInResult(result);
}
}
private void handleSignInResult(GoogleSignInResult result) {
if (result.isSuccess()) {
} else {
// Signed out, show unauthenticated UI.
// updateUI(false);
}
}
#Override
public void onConnected(Bundle bundle) {
}
#Override
public void onConnectionSuspended(int i) {
}
#Override
public void onConnectionFailed(ConnectionResult connectionResult) {
}
public void setmSignInButton(SignInButton mSignInButton) {
this.mSignInButton = mSignInButton;
}
}
After editing my manifest file according to the answer I got, my app now runs.
This is what my updated manifest file looks like:
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".LoginActivity"
android:exported="true">
<intent-filter >
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".RegisterActivity" />
<activity android:name=".MainActivity"
android:label="#string/title_activity_main"
android:theme="#style/AppTheme.NoActionBar"/>
</application>
You missed Intent filter in android manifest
Please replace your manifest with below code...
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<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"
android:exported="true"
android:label="#string/title_activity_main"
android:theme="#style/AppTheme.NoActionBar" >
<intent-filter >
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".RegisterActivity" />
<activity android:name=".LoginActivity" />
</application>
Intent filters show when to launch this activity. usually you will have one activity with intent filter that is to show that it is first activity when application is launched.

cant get sound to play on android splash screen (android studio)

i am trying to get a sound file to play when my splash screen is showing on my android app.... i have been trying to figure it out for a few hours now..... when i run my app it just skips the splash sreen all together now
here is my SplashScreen.java
package com.skapaidbeats.app.skapaidbeats;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import com.skapaidbeats.app.skapaidbeats.MainActivity;
import com.skapaidbeats.app.skapaidbeats.R;
public class SplashScreen extends Activity {
MediaPlayer music;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Thread timerThread = new Thread(){
public void run(){
try{
music= MediaPlayer.create(SplashScreen.this, R.raw.sound);
music.start();
sleep(3000);
}catch(InterruptedException e){
e.printStackTrace();
}finally{
Intent intent = new Intent(SplashScreen.this,MainActivity.class);
startActivity(intent);
}
}
};
timerThread.start();
}
#Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
music.release();
finish();
}
}
Here is my AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
package="com.skapaidbeats.app.skapaidbeats">
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".SplashScreen"
android:screenOrientation="portrait"
android:label="#string/icon_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.NoActionBar">
</activity>
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:screenOrientation="portrait"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name="com.startapp.android.publish.list3d.List3DActivity"
android:theme="#android:style/Theme" />
<activity
android:name="com.startapp.android.publish.AppWallActivity"
android:configChanges="orientation|keyboardHidden"
android:theme="#android:style/Theme.Translucent" />
<activity
android:name="com.startapp.android.publish.OverlayActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:theme="#android:style/Theme.Translucent" />
<activity
android:name="com.startapp.android.publish.FullScreenActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:theme="#android:style/Theme" />
</application>
</manifest>
Did you declare your activity in the manifest?
If you did, this question was asked before, try the following:
Android Sound not playing in splash screen
How to play audio in splash screen in android
You can try this
MediaPlayer player = new MediaPlayer();
player.setDataSource("/sdcard/audiotrack.mp3");
player.prepare();
player.start();

Parse Push "No Activity Found" on opening Push Notification

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>

Categories