Call an Intent on Android when home button is pressed - android

I'm developing an app that requires certain level of security. I need to have a feature when you press the home button and later enter in the app again, the app requires a password to continue where you've been staying before pushing the home button.
I already tried to do this, but when you call a new activity, the password screen is showed and I only need it when the home button is pressed:
#Override
public void onStop(){
super.onStop();
if (!isFinishing()) {
Intent i = new Intent(this, Register.class);
startActivity(i);
}
}
The normal flow is this:
Main->2nd Activity
but if I use the code that I showed, this is the flow:
Main->2nd Activity->Password Activity
It also works for home button but no for normal flow.
I already tried this and it works perfectly, but I don't want to add a new permission.

Related

how to know if a third-party app you open from your Android app is closed/exited

Some background information:
my Android app has four classes
:MainActivity,MyGcmListenerService,RegistrationIntentService, and RingCall.
If I presses on a button connected to my RPI3, then the RPI3 send a message titled "ringdoor" to my android app and method "onMessageReceived" in MyGcmListenerService takes care of the received message by starting the actvity "RingCall" that shows a blue ring call screen in this way:
if (message.equals("ringdoor")){
sendNotification(title, "The home doorbell rang");
Intent intent = new Intent(this,RingCall.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
The call screen has two options : "Accept" or "Decline". if I click on "Accept", then I go to the "Foscam" webcam app. the lines of code that does this are shown below:
answerButton = (Button) findViewById(R.id.answerButton);
answerButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent OpenFoscamApp= getPackageManager().getLaunchIntentForPackage("com.foscam.foscam");
startActivityForResult(OpenFoscamApp, 1); // CHANGED
mediaPlayer.stop();
finish();
}
});
My question:
When I open the "foscam" company webcam app from my android app by clicking on "Accept" and I decide to exit the app after that, how can I can know/check from my app that the webcam app was exited. are there any lines of that can do a check for that?
If you're using startActivityForResult, when the activity you launch is finished it will return via onActivityResult. If the user doesn't end the activity but just hits home or opens some other app, there is no notification.

Redirection to home after clicking on back button

I am creating an app, which will ask for password before opening any other app.
To start my activity i have created an intent which is having flags as ,
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
The locking/unlocking function is working properly,
but when i press back button it is not redirecting to home screen.
Make sure you have not finished your home screen activity.. or you can try the onBackPressed() method
#Override
public void onBackPressed() {
// INTENT FOR YOUR HOME ACTIVITY
}

Is there a delay in calling home screen intent?

I'm implementing an application locker for android.
I have the following code in my onPause() of authentication activity where user has to enter his password.
#Override
protected void onPause() {
super.onPause();
blnSwitchingActivity = true;
Intent intent = new Intent();
intent.setAction(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME)
.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
finish();
}
The following scenario creates a problem.
The user first clicks on any app.
The authentication activity is opened. The user can either enter his password or go back.
If he goes back, in onPause i'm calling home screen intent.
The problem is when the user clicks on home screen, he has to wait for a few seconds to open any other app.
My question: Why there is a delay in calling the home screen intent?
I'm not 100% sure of what your question is, but it sounds like some combination of android:noHistory=true and android:excludeFromRecents=true for the Activity in your manifest would do the trick for you.

Onclick back button the application stops

I have one problem regarding my app,when i click back button my application is getting finish.i need to prevent it.How could i make it .
#Override
public void onBackPressed() {
Log.d("CDA", "onBackPressed Called");
Intent setIntent = new Intent(Intent.ACTION_MAIN);
startActivity(setIntent);
}
I have tried something like this.But its not working .Actually what i need is when i will click back button ,the application should not finish it should run in background.can anybody help me out.#Thanks
Try doing it like this:
#Override
public void onBackPressed() {
Log.d("CDA", "onBackPressed Called");
Intent intent = new Intent();
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
startActivity(intent);
}
By doing this, your activity will not be destroyed (i.e. onDestroy will not be raised). But also, there's no guarantee that Android will preserve your activity for long.
In case, you are running a process that you want to keep on running even in background, then I would suggest you to go for Service or IntentService.
What do you mean by "it should run in background"? Why would you want that? If the user wants to keep the app opened, he can use the home button and the app won't be closed, if he presses the back button he wants to close the app. If want to have something that is still running even after the user closes the application you should take a look at Service http://developer.android.com/reference/android/app/Service.html, this will continue running even after the user closes the app

how to make another activity behave like home activity(first app launching actvity)

I have 4 activities in my application. I want back button to work normally on first three activities(i.e. going to previous screen on back button press); except the last.
I want that, when I press back button on fourth activity(screen), user should go to second Activity(Second screen). But the contents on that Activity should be same when user went from second screen to third screen.
And after that, when I press back button now on this second screen, I should exit application normally i.e. no system.exit() etc, rather like normally a application exists after back button press on first screen or first activity.
for third activity do this in manifest file:
android:noHistory="true"
and do this in fourth activity:
Button backButton = (Button)this.findViewById(R.id.back);
backButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
finish();
}
});
Try this:
Intent intent = new Intent(this, Abc.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);

Categories

Resources