Android Question close activity

ilan

Expert
Licensed User
Longtime User
hi

can i close my activity but not with activity.finish?

can i close my app the same way the home button close it?
so that userclosed will stay false in activity_pause

and on return only activity.resume will be called and not activity.create

thanx
 

ilan

Expert
Licensed User
Longtime User
i try it like this but i am getting an error:

B4X:
    Dim i As Intent
    i.Initialize("Intent.ACTION_MAIN","")
    i.AddCategory("Intent.CATEGORY_HOME")
    StartActivity(i)

this is the java code:

B4X:
Intent i = new Intent(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_HOME);
startActivity(i);
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
Using inline Java works. Not sure what the FLAG_ACTIVITY_NEW_TASK does (seen on StackOverflow)

B4X:
Sub myExitButton_Click
   CallSubDelayed(Me,"go") 
End Sub

Sub Go
   Dim J As JavaObject
   J.InitializeContext
   J.RunMethod("gogogo",Null)
End Sub

#if JAVA

import android.content.Intent;

public void gogogo(){
 
   Intent startMain = new Intent(Intent.ACTION_MAIN);
   startMain.addCategory(Intent.CATEGORY_HOME);
   startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
   startActivity(startMain);  
 
}


#end if
 
Upvote 0

ilan

Expert
Licensed User
Longtime User

Perfect!, thank you very much!! i tried it also with Java Object but could not get it to work. i guess its because i did not add:

B4X:
import android.content.Intent;

EDIT: @JordiCP, i think you should put that piece of code to the Code Snippets Forum.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…