我正在使用Android L转换在意图中传递ActivityOptions
包。
如何使用TaskStackBuilder
以相同的意图重现动画?
这是我目前的工作方法,只有一个Intent
:
startActivity(myIntent, ActivityOptions.makeSceneTransitionAnimation(this).toBundle());
这是我尝试使用TaskStackBuilder
:
TaskStackBuilder builder = TaskStackBuilder.create(this);
builder.addNextIntentWithParentStack(myIntent);
builder.startActivities(ActivityOptions.makeSceneTransitionAnimation(this).toBundle());
但动画会产生奇怪的效果,而不是“单一意图”版本。
我也尝试过:
builder.addNextIntent(myIntent);
而不是:
builder.addNextIntentWithParentStack(myIntent);
答案 0 :(得分:2)
尝试使用:
TaskStackBuilder.create (Context context)
返回一个新的TaskStackBuilder,用于启动由一系列活动组成的新任务堆栈。 参数 -
Context context
:将启动新任务堆栈或生成PendingIntent
的上下文。
返回TaskStackBuilder
- 一个新的TaskStackBuilder。
答案 1 :(得分:0)
在深入研究import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { RouterModule, Routes } from '@angular/router';
import { MatMomentDateModule } from '@angular/material-moment-adapter';
// import { MatButtonModule } from '@angular/material/button';
import { MatButtonModule, MatFormFieldModule, MatInputModule, MatRippleModule } from '@angular/material';
import { MatIconModule } from '@angular/material/icon';
import { MatDialogModule, MAT_DIALOG_DATA, MatDialogRef, MatDialog } from '@angular/material/dialog';
import { TranslateModule } from '@ngx-translate/core';
import { MatSelectModule } from '@angular/material';
import { FormsModule } from '@angular/forms';
import { FlexLayoutModule } from '@angular/flex-layout';
import 'hammerjs';
import { FuseModule } from '@fuse/fuse.module';
import { FuseSharedModule } from '@fuse/shared.module';
import { FuseProgressBarModule, FuseSidebarModule, FuseThemeOptionsModule } from '@fuse/components';
import { fuseConfig } from 'app/fuse-config';
import { AppComponent } from 'app/app.component';
import { LayoutModule } from 'app/layout/layout.module';
import { SampleModule } from 'app/main/sample/sample.module';
import { AddSalesPersonComponent } from './layout/components/Sales/add-sales-person/add-sales-person.component';
import { LoginComponent } from './layout/components/login/login.component';
import { MasterLayoutComponent } from './master-layout/master-layout.component';
import { NewLoanComponent } from './layout/components/loan/new-loan/new-loan.component';
import { ListSalesComponent } from './layout/components/Sales/list-sales/list-sales.component';
import { NewCustomerComponent } from './layout/components/customer/new-customer/new-customer.component';
import { CustomerListComponent } from './layout/components/customer/customer-list/customer-list.component';
import { NewOrganizationComponent } from './layout/components/organization/new-organization/new-organization.component';
import { ListOrganizationComponent } from './layout/components/organization/list-organization/list-organization.component';
import { NewProductComponent } from './layout/components/products/new-product/new-product.component';
import { ProductListComponent } from './layout/components/products/product-list/product-list.component';
import { NewAdminComponent } from './layout/components/admin/new-admin/new-admin.component';
import { ListAdminComponent } from './layout/components/admin/list-admin/list-admin.component';
import { LoanListComponent } from './layout/components/loan/loan-list/loan-list.component';
import { ReceivePaymentComponent } from './layout/components/payments/receive-payment/receive-payment.component';
import { MakePaymentComponent } from './layout/components/payments/make-payment/make-payment.component';
import { AuthGuard } from './guards/auth.guard';
import { TokenInterceptorService } from './services/token/token-interceptor.service';
const appRoutes: Routes = [
{
path: '',
component: MasterLayoutComponent,
children: [
{
path: '',
redirectTo: '/login',
pathMatch: 'full'
},
{
path: 'saveSalesPerson',
component: AddSalesPersonComponent
},
{
path: 'searchsalesperson',
component: ListSalesComponent
},
{
path: 'newcustomer',
component: NewCustomerComponent
},
{
path: 'searchcustomer',
component: CustomerListComponent,
canActivate: [AuthGuard]
},
{
path: 'neworganization',
component: NewOrganizationComponent
},
{
path: 'searchorganization',
component: ListOrganizationComponent
},
{
path: 'newproduct',
component: NewProductComponent
},
{
path: 'searchpoduct',
component: ProductListComponent
},
{
path: 'newloan',
component: NewLoanComponent
},
{
path: 'searchLoan',
component: LoanListComponent
},
{
path: 'newadmin',
component: NewAdminComponent
},
{
path: 'searchadmin',
component: ListAdminComponent
},
{
path: 'receivePayments',
component: ReceivePaymentComponent
},
{
path: 'makePayments',
component: MakePaymentComponent
},
]
},
{
path: 'login',
component: LoginComponent,
},
{
path: '**',
redirectTo: 'salesperson'
}
];
@NgModule({
imports: [
BrowserModule,
FlexLayoutModule,
MatButtonModule,
MatFormFieldModule,
FormsModule,
MatInputModule,
MatRippleModule,
MatSelectModule,
BrowserAnimationsModule,
HttpClientModule,
MatDialogModule,
RouterModule.forRoot(appRoutes),
TranslateModule.forRoot(),
// Material moment date module
MatMomentDateModule,
// Material
MatButtonModule,
MatIconModule,
// Fuse modules
FuseModule.forRoot(fuseConfig),
FuseProgressBarModule,
FuseSharedModule,
FuseSidebarModule,
FuseThemeOptionsModule,
// App modules
LayoutModule,
SampleModule
],
declarations: [
AppComponent,
MasterLayoutComponent
],
exports: [
MatButtonModule,
MatFormFieldModule,
MatInputModule,
MatRippleModule,
],
bootstrap: [
AppComponent
],
providers: [AuthGuard, {
provide: HTTP_INTERCEPTORS,
useClass: TokenInterceptorService,
multi: true
}, { provide: MatDialogRef, useValue: {} },
]
})
export class AppModule {
}
的实现之后,问题在于它迫使将TaskStackBuilder
添加到堆栈的第一个intent中,这产生了奇怪的效果,因此请使用以下内容启动堆栈:
Intent.FLAG_ACTIVITY_CLEAR_TASK
这里的想法是仍然使用Intent[] intents = TaskStackBuilder.create(this)
.addNextIntentWithParentStack(myIntent)
.getIntents();
if (intents.length > 0) {
intents[0].setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);// Or any other flags you want, but not the `.._CLEAR_..` one
}
// `this` inside current activity, or you can use App's context
this.startActivities(intents, ActivityOptions.makeSceneTransitionAnimation(this).toBundle());
创建意图栈,然后删除TaskStackBuilder
添加到第一意图的奇怪的Intent.FLAG_ACTIVITY_CLEAR_TASK
,然后手动开始活动使用您想要的任何上下文。