How to start another activity after a splash screen in android studio - java

Hi everyone I'm studying now and developing a app in android studio. My problem is i can't proceed to my log in activity after splash screen. I already look in the net and stackoverflow and applied it, but still same error. I appreciate for the help and answer.
Here are some of my code
SplashScreen.java
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
final Intent mainIntent = new Intent(SplashScreen.this, Login.class);
SplashScreen.this.startActivity(mainIntent);
SplashScreen.this.finish();
}
},3000);
}
Login.java
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
Intent intent = new Intent(Login.this, MainActivity.class);
startActivity(intent);
finish();
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="#mipmap/logo"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<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=".Login"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".Login"/>
</activity>
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="com.ex.app.MainActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
where did i go wrong ?

As you have written code to move to MainActivity on the method onCreate of Login.java
Intent intent = new Intent(Login.this, MainActivity.class);
startActivity(intent);
finish();
Comment this line or keep it on the click of SignIn button

Your login activity just directs you to the MainActivity on create
Look at these lines
Intent intent = new Intent(Login.this, MainActivity.class);
startActivity(intent);

It is redirecting to MainActivity directly as in your LoginActivity onCreate you have written
Intent intent = new Intent(Login.this, MainActivity.class);
startActivity(intent);
finish();
without any condition. Make it conditional by putting your login check conditions and criteria
if (<logged_in_your_condition_Check>){
Intent intent = new Intent(Login.this, MainActivity.class);
startActivity(intent);
finish();
}

why you require below lines in Login.class
Intent intent = new Intent(Login.this, MainActivity.class);
startActivity(intent);
finish();
if you are using finish() in onCreate() then it will immediately called onDestroy() and that dosen't make any sense.
remove above given code from onCreate your code will work

in manifest write:
<activity
android:name=".MySplashActivity"
android:noHistory="true"
..... >
....
</activity>
then in create() or somewhere different cal the method:
private static int SPLASH_TIME_OUT=2000;
private void nextScreen() {
new Handler().postDelayed(()-> {
Intent intent = new Intent(MySplashaActivity.this, NextActivity.class);
startActivity(intent);
finish();
}, SPLASH_TIME_OUT);
}

Related

Implicit Internal Intent vulnerability. Can't set package name

I have that vulnerability according to google play console.
It's supposed that the solution is to add .setPackage() or .setClassName() to the intent but now the activity is not being recognized. How can I use this function?
The intent as it was with the vulnerability is this:
#Override
public void onBackPressed() {
super.onBackPressed();
Intent intent = new Intent("independent.dev.ui.mainactivity");
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
}
The solution that I tried adding the package name:
#Override
public void onBackPressed() {
super.onBackPressed();
Intent intent = new Intent("independent.dev.ui.mainactivity");
intent.setPackage("independent.dev.ui.Activities");
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
}
my AndroidManifest.xml is this
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="independent.dev.ui.Activities">
.
.
.
<activity
android:name=".MainActivity"
android:configChanges="orientation|keyboardHidden"
android:label="Menu Principal"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="independent.dev.ui.mainactivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
How can I set the package so I can navigate and delete this vulnerability?

Alarm Manager not woking

I am using AlarmManager on clicking floatingActionButton but it is not calling the alarm class. I tested the floatingActionButton via Toasts but it is working fine but Toast and vibrator in My_Alarm Class is not working even tough i have enebled permission in Manifests. Kindly point out the problem!
Below code main activity (Alarm Manager in floatingActionButton)
floatingActionButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, AlarmManager.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(MainActivity.this,5,intent,0);
sendBroadcast(intent);
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+1000,pendingIntent);
}
});
}
This is my Alarm class (Toast and Vibrate not working)
public class My_Alarms extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "Fuck This Shit", Toast.LENGTH_LONG).show();
Vibrator v = (Vibrator)context.getSystemService(context.VIBRATOR_SERVICE);
v.vibrate(10000);
}
}
And this is my Manifest file (I have enabled permission)
<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/AppTheme">
<activity android:name=".Activity_Time_Setting"
android:grantUriPermissions="true"
></activity>
<activity android:name=".MainActivity">
android:grantUriPermissions="true"
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
android:grantUriPermissions="true"
</intent-filter>
</activity>
<receiver android:name=".My_Alarms"/>
</application>
Replace this line of code :
Intent intent = new Intent(MainActivity.this, AlarmManager.class);
with this :
Intent intent = new Intent(MainActivity.this, My_Alarms.class);
Also you don't need to use
sendBroadcast(intent);
this line because you are already passing intent in pending intent
At last try to to remove toast from your broadcast reciver

scheduling alarmmanager not working on reboot my phone

It's toasting until I didn't restart my phone but after restarting broadcastreceiver2 doesn't receive and nothing happens.
I followed http://stacktips.com/tutorials/android/how-to-start-an-application-at-device-bootup-in-android and many other but nothing happens.
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.k2.alarmmanagerdemo">
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<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/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="com.k2.alarmmanagerdemo.MyBroadcastReceiver"
android:enabled="true">
</receiver>
<receiver android:name="com.k2.alarmmanagerdemo.BroadCastRecevier2"
android:enabled="true"
android:exported="true"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.QUICKBOOT_POWERON"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
</application>
</manifest>
MainActivity.java
public class MainActivity extends Activity {
Button b1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1=(Button) findViewById(R.id.button1);
b1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
startAlert();
}
});
}
public void startAlert() {
EditText text = (EditText) findViewById(R.id.time);
int i = Integer.parseInt(text.getText().toString());
Intent intent = new Intent(this, MyBroadcastReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(
this.getApplicationContext(), 234324243, intent, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,System.currentTimeMillis(),
1000 * 5,pendingIntent);
Toast.makeText(this, "Alarm set in " + i + " seconds",Toast.LENGTH_LONG).show();
}
}
MyBroadcastReceiver.java
public class MyBroadcastReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "Alarm...." + System.currentTimeMillis(), Toast.LENGTH_SHORT).show();
Log.i("Alarm.", "alarm called" + System.currentTimeMillis());
}
}
BroadCastRecevier2.java
public class BroadCastRecevier2 extends BroadcastReceiver {
MainActivity activity = new MainActivity();
#Override
public void onReceive(Context context, Intent intent) {
activity.startAlert();
if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) {
Intent i = new Intent();
i.setClassName("com.k2.alarmmanagerdemo",
"com.k2.alarmmanagerdemo.MainActivity");
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
Toast.makeText(context, "BOOT", Toast.LENGTH_SHORT).show();
Log.i("myboot","boot compleated inside");
}
}
}
Remove this line from your <receiver> declaration for BroadcastReceiver2:
android:permission="android.permission.RECEIVE_BOOT_COMPLETED"
That line in the <receiver> tag is telling the system that only packages which have this permission are allowed to send your class the Intent. Its' likely confusing the system and preventing the Intent from being sent to your receiver.
You may also find this article helpful when learning about alarms and the boot complete receiver.

android.content.ActivityNotFoundException: No Activity found to handle Intent

please help , when i run the app, the app launch a Fatal Error im learning
just i create a instat with a call but not run, (sorry for my english)
.......................................................................
my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.octa.appprueba3">
<uses-permission android:name="android.permission.CALL_PHONE" />
<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" />
<category android:name="android.intent.category.APP_CONTACTS" />
</intent-filter>
</activity>
<activity android:name=".SecondActivity"></activity>
</application>
</manifest>
my code:
public class SecondActivity extends AppCompatActivity {
private EditText editPhoneText;
private ImageButton imageCallButton;
private final int PHONE_CALL_CODE = 100;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
editPhoneText = (EditText) findViewById(R.id.editTextPhone);
imageCallButton = (ImageButton) findViewById(R.id.imageCallButton1);
imageCallButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
implicito();
}
});
}
public void implicito(){
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("Tel: 9999999" ));
startActivity(intent);
}
}
You may want to check whether your device can handle your intent by doing this:
PackageManager packageManager = getPackageManager();
if (intent.resolveActivity(packageManager) != null) {
startActivity(intent);
} else {
Log.d(TAG, "Cannot handle this intent");
}
What's more, if you are placing a call like so, there is NO need to declare the permission in your manifest:
<uses-permission android:name="android.permission.CALL_PHONE" />
Because you are not directly calling someone within your app. You are actually transferring the "duty" to other apps which can handle your intent to call. This doesn't need a permission.
To directly make a call within your app, the intent should be Intent.ACTION_CALL, which needs the permission you declared.
Hope this will help.
There is no activity on your device that handles ACTION_DIAL for a Tel: scheme. Try:
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:9999999" ));
Case and whitespace are important when assembling a Uri.
Also note that even my revised Intent will not work on all devices, such as on an Android tablet that lacks a dialer.

Android intent not starting new activity?

I'm trying to do something rather simple here, just launch a new activity from my main one. Here's the code:
public class mainActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent i = new Intent(mainActivity.this, testActivity.class);
startService(i);
}
}
///////////////// next file /////////////////
public class testActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test);
Toast.makeText(this, "testActivity started", Toast.LENGTH_SHORT).show();
}
}
///////////////// manifest section ///////////////////
<application android:icon="#drawable/icon" android:label="#string/app_name">
<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:name=".testActivity" />
But I never see the Toast from testActivity - what gives?
You want to use startActivity instead of startService
Intent i = new Intent(mainActivity.this, testActivity.class);
startActivity(i);
To start an activity you should use startActivity() instead of startService().
You'll also have to make sure the testActivity is listed in your android manifest.
If the activity is still running in the background, it gets called and only the onResume() gets called, not the onCreate();
check the lifecycle here: http://developer.android.com/guide/topics/fundamentals/activities.html#Lifecycle

Categories

Resources