Voltando ao TabActivity anterior
Como posso explicar o meu problema?
Eu tenho um aplicativo usando guias (por Intents, não visualizações). Eu implementei a navegação dentro de cada visualização sem problemas, mas preciso iniciar o player de vídeo a partir de um ListView dentro de uma atividade no modo de tela cheia e modo paisagem (sem guias). Mas quando eu quero viver o player (pressionando a tecla Voltar ou chamando Concluir ();), meu aplicativo é fechado (sem exceções no LogCat) e retornado à tela principal. Então, o que eu preciso é que, ao sair da Atividade em tela cheia (lançada para o player), volte ao meu aplicativo, com as guias.
Aqui está o meu código:
//Main activity :
package com.ccn;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TabHost;
public class CCNMain extends TabActivity {
public static TabHost tabHost;
static CCNMain myActivity = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myActivity = this;
Resources res = getResources();
tabHost = getTabHost();
TabHost.TabSpec spec; // reusable tabspec for each tab
Intent intent;
intent = new Intent().setClass(this, NewsGroup.class);
spec = tabHost.newTabSpec("nnews")
.setIndicator("A la une",res.getDrawable(R.drawable.home))
.setContent(intent);
tabHost.addTab(spec);
/*intent = new Intent().setClass(this, ArticlesGroup.class);
spec = tabHost.newTabSpec("aarticles")
.setIndicator("Articles",res.getDrawable(R.drawable.articles))
.setContent(intent);
tabHost.addTab(spec);*/
intent = new Intent().setClass(getApplicationContext(), ContactGroup.class);
spec = tabHost.newTabSpec("vvideos")
.setIndicator("Vidéos",res.getDrawable(R.drawable.video))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(getApplicationContext(), ContactGroup.class);
spec = tabHost.newTabSpec("ccontact")
.setIndicator("Contact",res.getDrawable(R.drawable.contact))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
}
}
//ContactGroup :
package com.ccn;
import java.util.ArrayList;
import android.app.ActivityGroup;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
public class ContactGroup extends ActivityGroup {
// Keep this in a static variable to make it accessible for all the nested activities, lets them manipulate the view
public static ContactGroup groupContact;
// Need to keep track of the history if you want the back-button to work properly, don't use this if your activities requires a lot of memory.
private ArrayList<View> history;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.history = new ArrayList<View>();
groupContact = this;
// Start the root activity within the group and get its view
View view = getLocalActivityManager().startActivity("idHoraireActivity", new
Intent(this,ContactActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
.getDecorView();
// Replace the view of this ActivityGroup
replaceView(view);
, }
public void replaceView(View v) {
// Adds the old one to history
history.add(v);
// Changes this Groups View to the new View.
setContentView(v);
}
public void back() {
if(history.size() > 1) {
history.remove(history.size()-1);
setContentView(history.get(history.size()-1));
}else {
finish();
}
}
//@Override
public void onBackPressed() {
ContactGroup.groupContact.back();
return;
}
}
//ContactActivity:
package com.ccn;
import java.io.IOException;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.MediaController;
import android.widget.Toast;
import android.widget.VideoView;
public class ContactActivity extends Activity {
static ContactActivity bidule = null;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.videos);
bidule = this;
Button btn = (Button) findViewById(R.id.button1);
btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i = new Intent();
i.setClass(getApplicationContext(), videoPlayerActivity.class);
//i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
bidule.startActivity(i);
ContactActivity.this.startActivityForResult(i, 0);
}
});
}
}
//VideoPlayerActivity:
package com.ccn;
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.MediaController;
import android.widget.VideoView;
public class videoPlayerActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.videos);
//the VideoView will hold the video
String url = // Video url;
Button btn = (Button) findViewById(R.id.button1);
btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
finish();
}
});
}
}
E aqui meu manifesto:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ccn"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".CCNMain"
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="ArticlesGroup"></activity>
<activity android:name="ContactGroup"></activity>
<activity android:name="NewsGroup"></activity>
<activity android:name="NewsActivity"></activity>
<activity android:name="ArticlesAvtivity"></activity>
<activity android:name="ContactActivity"></activity>
<activity android:name="videoPlayerActivity" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:screenOrientation="landscape"></activity>
</application>
</manifest>
Obrigado pela ajuda. Meu palpite: tem a ver com o local em que chamo sinalizadores startActivity e Intent. O que você acha