Android onCreate not firing on new activity - android

Hi there I am trying to execute some code when I change to the next activity, but it does not seem to work. The Previous activity is a login page if the user is already logged in it goes straight to the new activity. But the onCreate does not seem to fire.
Main Activity
public class MainActivity extends AppCompatActivity {
private View mMainView;
private Meteor mMeteor;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setTitle("ACTIVITY");
Log.d("SimpleActivity","OnCreate Started");
if(MeteorSingleton.getInstance().isConnected()){
Log.d("Connection", "Connected");
}else{
Log.d("Connection", "Not Connected");
}
}
........
The strange thing is the setTitle works but none of the logs.
Here is some code from the previous login in page.
#Override
public void onConnect(boolean signedInAutomatically) {
Log.i("Connection", "Connected to host server");
if (mMeteor.isLoggedIn()) {
openMainScreen(mLoginFormView);
}
}
public void openMainScreen(View view) {
Intent dashboard = new Intent(getApplicationContext(), MainActivity.class);
startActivity(dashboard);
}
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="system.carproject.adam.ams">
<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<!--
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Google Maps Android API v2, but you must specify either coarse or fine
location permissions for the 'MyLocation' functionality.
-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<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: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=".MainActivity"
android:label="Activity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="#string/google_maps_key" />
<activity
android:name=".MapsActivity"
android:label="#string/title_activity_maps"></activity>
</application>
</manifest>
If someone could educate me on this would be great. Can seem to figure it out.
Thanks

You have created two LAUNCHER Activities and that's created two App Icon in your Device so if you think its open directly MainActvity then its possible if you click on second app icon in your device for same application . check your device .
first remove LAUNCHER mode from MainActvity in Android Manifest and then you have to add manual check in your login Activity onCreate() for login status and then startActvity() MainActivty if login status is true.

try removing the intent filter tag from activity tag of MainActivity in Manifest:-
<activity android:name=".MainActivity"
android:label="Activity"> </activity>

Related

Why Android App - Re-started when the application stopped form the Android Studio?

I am new to Android Development and I am developing an application to scan barcode using google vision API. In the application, I have three screens Splash Screen, Main Screen with two fragments (Scan & History) and Scanned Result. From the scan fragment, I am opening an activity called "ScannedResult" as soon as application scanned the barcode to show the result.
Now the problem is when I run the application from the Android Studio to the device.
[Scenario# 0] (From the Main activity screen app stopping that is the correct case)
Run the app
Splash Screen -> Main Screen
Shows scan fragment and run successful flow
Now, STOP the application from the Android Studio.
Application stopped
[Scenario# 1] (But from ScannedResult activity app stops and start again why?)
Run the app
Splash Screen -> Main Screen
Shows scan fragment and run successful flow
Now, Scan a Bar or QR Code then open ScannedResult (activity).
Now, STOP the application from the Android Studio.
Application stopped and show Black Screen
Application STARTED again and shows the Main Screen (Why it is starting again? I want to stop the application in this case).
Here I am suspecting something is wrong. Ideally, it must be stopped. Please help to identify where I am making mistake in the application.
Here is the Manifest.xml file
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myapp.powertools.barcodescan">
<application
android:allowBackup="false"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".CreatePaypalUrl"
android:parentActivityName=".MainActivity"></activity>
<activity
android:name=".CreateVcardForm"
android:parentActivityName=".MainActivity" />
<activity
android:name=".CreateLocationForm"
android:parentActivityName=".MainActivity" />
<activity
android:name=".CreateWifiForm"
android:parentActivityName=".MainActivity" />
<activity
android:name=".CreateEventForm"
android:parentActivityName=".MainActivity" />
<activity
android:name=".CreateSmsForm"
android:parentActivityName=".MainActivity" />
<activity
android:name=".CreateEmailForm"
android:parentActivityName=".MainActivity" />
<activity
android:name=".CreateTelephoneForm"
android:parentActivityName=".MainActivity" />
<activity
android:name=".CreateWebsiteForm"
android:parentActivityName=".MainActivity" />
<activity android:name=".Main2Activity" />
<activity
android:name=".GenerateQrCode"
android:parentActivityName=".MainActivity" />
<activity
android:name=".CreateTextForm"
android:parentActivityName=".MainActivity" />
<activity
android:name=".ScannedResult"
android:parentActivityName=".MainActivity" />
<activity
android:name=".SplashScreen"
android:label="#string/app_name" 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=".MainActivity"
android:theme="#style/AppTheme.NoActionBar" />
<meta-data
android:name="com.google.android.gms.vision.DEPENDENCIES"
android:value="barcode" />
</application>
<uses-feature android:name="android.hardware.camera.front" android:required="false" />
<uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
</manifest>
Scan.java file
barcodeDetector.setProcessor(new Detector.Processor<Barcode>() {
#Override
public void release() {
}
#Override
public void receiveDetections(Detector.Detections<Barcode> detections) {
final SparseArray<Barcode> qrCodes = detections.getDetectedItems();
if (qrCodes.size() > 0) {
if (isScanned == false) {
barcodeDetector.release();
isScanned = true;
String dataType = getBarcodeType(qrCodes.valueAt(0));
String dataValue = qrCodes.valueAt(0).displayValue;
String rawValue = qrCodes.valueAt(0).rawValue;
Intent intentScannedResult = new Intent(getActivity(), ScannedResult.class);
intentScannedResult.putExtra("barcode_raw_value", rawValue);
intentScannedResult.putExtra("barcode_value", dataValue);
intentScannedResult.putExtra("barcode_type", dataType);
intentScannedResult.putExtra("is_scanner", "1");
startActivity(intentScannedResult);
}
}
}
});

crash new android process stops entire application

I have a android application, which has mainctivty and it starts other activity "secondactivity", this secondactivity I am starting in a new process by adding android:process=":SecondProcess" in manifestfile.
I am starting second activity using below code.
Intent ssIntent = new Intent(getApplicationContext(), SecondActivity.class);
startActivity(ssIntent);
below is my manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.test">
<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<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="com.example.test.SecondActivity"
android:process=":SecondProcess"
android:label="#string/title_activity_basic"
android:theme="#style/AppTheme.NoActionBar">
</activity>
</application>
There is crash(I added for testing) in the Secondactivity, now as per my understanding only secondprocess Should gets killed whenever crash happens in secondactivity as its running in separate process , but in my test entire android application gets stopped .
Could you please let me know is there a way to handle such a way that only second process should killed and it should not disturb the complete application.
I can handle with try catch, but my goal is to make sure first Activity will be still alive even after second one crashes..
User try/catch to handle the error in SecondActivity...so that it won't crash the whole app.
try {
//Code that creates error in SecondActivity
}catch(Exception e) {
//Close the activity after exception
finish();
}

Passing data from one Activity to another Activity when using speech recognition android

I have the next code in my Android Studio project
#Override
public void startActivity(Intent intent) {
boolean bandera = Intent.ACTION_SEARCH.equals(intent.getAction()) || RecognizerIntent.ACTION_RECOGNIZE_SPEECH.equals(intent.getAction());
if (bandera) {
intent.putExtra("usuario", usuarioIS);
}
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
super.startActivity(intent);
}
When I search, I use the putExtra method to send some info of a user from the actual activity to another activity. But when I use the speech recognition, the startActivity method throws me an exception in my phone and android studio doesn't give info about the exception. Does anyone know why the speech recognition does not work?
This is my Manifest.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.ivan.saberespoder" >
<!-- To access Google+ APIs: rex -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- To retrieve OAuth 2.0 tokens or invalidate tokens to disconnect a user. This disconnect *** option is required to comply with the Google+ Sign-In developer policies -->
<uses-permission android:name="android.permission.USE_CREDENTIALS" /> <!-- To retrieve the account name (email) as part of sign-in: -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" /> <!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<activity
android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="#string/app_name"
android:theme="#android:style/Theme.Translucent.NoTitleBar" />
<application
android:allowBackup="true"
android:icon="#mipmap/logopeq"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_app_id" />
<activity
android:name=".PantallaPrincipal"
android:label="iShots" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="android.app.default_searchable"
android:value=".Busqueda" />
</activity>
<activity
android:name=".Busqueda"
android:label="#string/title_activity_busqueda" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="#xml/searchable" />
</activity>
<activity
android:name=".LoginActivity"
android:label="#string/title_activity_login"
android:windowSoftInputMode="adjustResize|stateHidden" >
</activity>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name=".Registro"
android:label="#string/title_activity_menu_usuario" >
</activity>
<activity
android:name=".MostrarShot"
android:label="#string/title_activity_mostrar_shot" >
</activity>
<activity
android:name=".Settings"
android:label="#string/title_activity_settings" >
</activity>
<activity
android:name=".AgregarShot"
android:label="#string/title_activity_agregar_shot" >
</activity>
<activity
android:name=".ProfileActivity"
android:label="#string/title_activity_profile" >
</activity>
<activity
android:name=".HelpActivity"
android:label="#string/title_activity_help" >
</activity>
<activity
android:name=".AboutActivity"
android:label="#string/title_activity_about" >
</activity>
</application>
</manifest>
I'm new using Android Studio
public static final String ACTION_RECOGNIZE_SPEECH
Added in API level 3 Starts an activity that will prompt the user for
speech and send it through a speech recognizer. The results will be
returned via activity results (in onActivityResult(int, int, Intent),
if you start the intent using startActivityForResult(Intent, int)), or
forwarded via a PendingIntent if one is provided.
Starting this intent with just startActivity(Intent) is not supported.
You must either use startActivityForResult(Intent, int), or provide a
PendingIntent, to receive recognition results.
Doc source
So try dealing with startActivityForResult();
Secondly, you should add a permission to Manifest :
<uses-permission android:name="android.permission.RECORD_AUDIO" />
Third, if you define Action RecognizerIntent.ACTION_RECOGNIZE_SPEECH, so the system will try to open Activity which can handle it. So for your next Activity you should add this "skill" to Manifest. Source. If you don't want, just handle this Activity as usual with Intent.ACTION_VIEW.
One nice answer for you in addition. This will fit you I guess.
Try it out. Hope it helps.

phonegap app loads first page upon screen orientation change

i am developing an android app using phonegap. i have multiple pages in the app and a single activity. whenever i change the orientation of the device, no matter which page i am on, the app loads the first page which is shown when the app is launched. i assumed it was because i had not overriden the onResume() method in the activity, but even that failed to solve the problem.
EDIT: This issue does not arise if the app is paused and the resumed.
My activity:
public class MainScreen extends DroidGap {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.loadUrl("file:///android_asset/www/landing.html");
}
#Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
}
}
EDIT: Added Manifest file
My Manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.me.code"
android:versionCode="5"
android:versionName="1.4" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="com.miniorange.authenticator.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.miniorange.authenticator.permission.C2D_MESSAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.miniorange.authenticator.MainActivity"
android:label="#string/app_name" >
</activity>
<activity android:name="com.miniorange.authenticator.MainScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.plugin.gcm.PushHandlerActivity"/>
<receiver android:name="com.plugin.gcm.CordovaGCMBroadcastReceiver" 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="com.me.code" />
</intent-filter>
</receiver>
<service android:name="com.plugin.gcm.GCMIntentService" />
</application>
</manifest>
what may be the solution to this problem?
sorry ... ( answering it late :D )
I had this problem with my app :
When I change the orientation, activity reloads ...
And I found this solution :
add this attribute to your <activity> tags :
android:configChanges="orientation"
suggestion ... use this insted (better) :
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale"
==========================================
information about solution :
what is the reason .. (?)
It'll say to application that you want to handle this changes (orientation, keyboardHidden, keyboard, screenSize, locale, etc.) yourself.

Android parse.com Can't receive push notification

I can't receive push notifications, using parse.com service.
I used a quick guide trying to solve my problem. I was trying to use channel this specified name and "" as a channel name. Also i found Cannot receive push notifications in Android with trigger.io and parse.com
I succeed to send object to parse.com, and to subscribe for notifications (at least I can see my app in DataBrowser on parse.com)
public class ParseStarterProjectActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
PushService.subscribe(this, "push", TestParse.class);
PushService.setDefaultPushCallback(this, TestParse.class);
}
}
public class ParseApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
Parse.initialize(this, my_id, my_client_key);
}
}
public class TestParse extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.parse);
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.parse.starter"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="4"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:name="ParseApplication"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<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>
<activity
android:name=".ParseStarterProjectActivity"
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=".TestParse"
android:label="#string/app_name" />
</application>
</manifest>
Recently I've noticed LogCat errors:
02-21 18:17:45.381: ERROR/Trace(8952): error opening trace file: No such file or directory (2)
02-21 18:17:48.534: ERROR/com.parse.PushService(8888): unknown host
I really want to receive notifications. What am I doing wrong?
Parse employee here. In order to handle increased load on our push service, we increased the number of machines serving push.parse.com. Some ISPs started having issues when DNS resolution returned this many servers. Last Friday afternoon, we launched a custom DNS server which works around these issues with 3rd party DNS resolution. This should no longer be an issue.

Categories

Resources